IJsonDataConnectionProviderService.GetJsonDataConnection(String) Method
Gets a connection by name.
Namespace: DevExpress.DataAccess.Json
Assembly: DevExpress.DataAccess.v24.1.dll
NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap
Declaration
Parameters
Name | Type | Description |
---|---|---|
name | String | A connection name. |
Returns
Type | Description |
---|---|
JsonDataConnection | A JSON connection. |
Remarks
The GetJsonDataConnection method resolves a connection name to a JSON connection.
The following code retrieves a connection string from the dictionary for the given connection name, creates and returns the JsonDataConnection object.
using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.DataAccess.Json;
using DevExpress.DataAccess.Web;
using ReportWizardCustomizationServiceAspNetCoreExample.Data;
namespace ReportWizardCustomizationServiceAspNetCoreExample.Services
{
public class CustomJsonDataConnectionProviderFactory : IJsonDataConnectionProviderFactory {
protected ReportDbContext DbContext { get; }
public CustomJsonDataConnectionProviderFactory(ReportDbContext dbContext) {
DbContext = dbContext;
}
public IJsonDataConnectionProviderService Create() {
return new WebDocumentViewerJsonDataConnectionProvider(DbContext.JsonDataConnections.ToList());
}
}
public class WebDocumentViewerJsonDataConnectionProvider : IJsonDataConnectionProviderService
{
readonly IEnumerable<DataConnection> jsonDataConnections;
public WebDocumentViewerJsonDataConnectionProvider(IEnumerable<DataConnection> jsonDataConnections) {
this.jsonDataConnections = jsonDataConnections;
}
public JsonDataConnection GetJsonDataConnection(string name) {
var connection = jsonDataConnections.FirstOrDefault(x => x.Name == name);
if(connection == null)
throw new InvalidOperationException();
return CustomDataSourceWizardJsonDataConnectionStorage.CreateJsonDataConnectionFromString(connection);
}
}
}
For more information and code examples, review the following help topic: JSON Data - Register Connections.
See Also