翻譯|行業資訊|編輯:龔雪|2023-08-21 11:24:46.660|閱讀 104 次
概述:本文總結了v23.1中針對DevExpress報表和BI Dashboard產品中使用的SQL和實體框架數據源引入的一系列增強,歡迎下載最新版體驗~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
DevExpress Reporting是.NET Framework下功能完善的報表平臺,它附帶了易于使用的Visual Studio報表設計器和豐富的報表控件集,包括數據透視表、圖表,因此您可以構建無與倫比、信息清晰的報表。
本文總結了v23.1中針對DevExpress報表和BI Dashboard產品中使用的SQL和實體框架數據源引入的一系列增強。
DevExpress技術交流群8:523159565 歡迎一起進群討論
使用實體框架的ASP.NET Core應用程序將數據作為 對象提供給報表/儀表板。
此對象在HTTP請求的范圍內工作,該請求的生存期與報表/儀表板的生存期不同。在HTTP請求上下文中創建一個報告,并啟動一個后臺線程來獲取數據和創建文檔。由于在初始HTTP請求完成后報表需要數據,并且儀表板在控件中使用已兌現的數據源,因此不能使用Entity Framework創建的默認DbContext實例(在HTTP請求的范圍內)。
現在為開發人員提供了一種方法,可以從綁定到實體框架數據源的儀表板/報表的ASP.NET Core依賴注入容器中解析適當的實體框架核心上下文。
下面的新API用于創建自定義服務,從依賴注入容器中返回上下文對象:
下面的代碼片段實現了一個自定義服務,允許獲得適當的EF Core上下文:
using DevExpress.Data.Entity; using DevExpress.DataAccess.Web; using System; using Microsoft.Extensions.DependencyInjection; namespace WebEFCoreApp.Services { public class CustomEFContextProviderFactory : IEFContextProviderFactory { private readonly IServiceProvider serviceProvider; public CustomEFContextProviderFactory(IServiceProvider serviceProvider) { this.serviceProvider = serviceProvider; } public IEFContextProvider Create() { return new CustomEFContextProvider(serviceProvider.CreateScope()); } } public class CustomEFContextProvider : IEFContextProvider, IDisposable { private readonly IServiceScope scope; public CustomEFContextProvider(IServiceScope scope) { this.scope = scope; } public object GetContext(string connectionName, Type contextType) { // Returns the context for the specified `EFDataSource.ConnectionName`. if (connectionName == "efCoreConnection") return scope.ServiceProvider.GetRequiredService(contextType); return null; } public void Dispose() { scope.Dispose(); } }
在依賴注入容器中注冊上下文和factory實現:
namespace DXWebApplication1 { public class Startup { public Startup(IConfiguration configuration, IWebHostEnvironment hostingEnvironment) { Configuration = configuration; } public void ConfigureServices(IServiceCollection services) { // ... services.ConfigureReportingServices(configurator => { configurator.ConfigureWebDocumentViewer(viewerConfigurator => { // ... viewerConfigurator.RegisterEFContextProviderFactory(); }); configurator.UseAsyncEngine(); }); services.AddDbContext(options => options.UseSqlite("Data Source=file:Data/nwind.db"), ServiceLifetime.Transient); } } }
v23.1附帶了新的和接口。
這些接口允許您在建立到數據庫的連接時攔截、修改和/或抑制SQL操作和命令,該列表包括低級數據庫操作,例如在會話上下文中執行命令或設置鍵值對。一旦連接打開,您就可以在會話上下文中存儲值并執行所需的請求。
設置還添加了 和 屬性,來幫助指定用于將一個事務與另一個事務隔離的隔離級別。
您可以將IsolationLevel設置為以下值當中的一個:
每次執行查詢時,將打開相應的事務類型(None除外)。一旦請求被執行,事務就會立即關閉。
這一策略的好處如下:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網