翻譯|行業(yè)資訊|編輯:龔雪|2023-08-21 11:24:46.660|閱讀 104 次
概述:本文總結(jié)了v23.1中針對DevExpress報(bào)表和BI Dashboard產(chǎn)品中使用的SQL和實(shí)體框架數(shù)據(jù)源引入的一系列增強(qiáng),歡迎下載最新版體驗(yàn)~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
DevExpress Reporting是.NET Framework下功能完善的報(bào)表平臺(tái),它附帶了易于使用的Visual Studio報(bào)表設(shè)計(jì)器和豐富的報(bào)表控件集,包括數(shù)據(jù)透視表、圖表,因此您可以構(gòu)建無與倫比、信息清晰的報(bào)表。
本文總結(jié)了v23.1中針對DevExpress報(bào)表和BI Dashboard產(chǎn)品中使用的SQL和實(shí)體框架數(shù)據(jù)源引入的一系列增強(qiáng)。
DevExpress技術(shù)交流群8:523159565 歡迎一起進(jìn)群討論
使用實(shí)體框架的ASP.NET Core應(yīng)用程序?qū)?shù)據(jù)作為 對象提供給報(bào)表/儀表板。
此對象在HTTP請求的范圍內(nèi)工作,該請求的生存期與報(bào)表/儀表板的生存期不同。在HTTP請求上下文中創(chuàng)建一個(gè)報(bào)告,并啟動(dòng)一個(gè)后臺(tái)線程來獲取數(shù)據(jù)和創(chuàng)建文檔。由于在初始HTTP請求完成后報(bào)表需要數(shù)據(jù),并且儀表板在控件中使用已兌現(xiàn)的數(shù)據(jù)源,因此不能使用Entity Framework創(chuàng)建的默認(rèn)DbContext實(shí)例(在HTTP請求的范圍內(nèi))。
現(xiàn)在為開發(fā)人員提供了一種方法,可以從綁定到實(shí)體框架數(shù)據(jù)源的儀表板/報(bào)表的ASP.NET Core依賴注入容器中解析適當(dāng)?shù)膶?shí)體框架核心上下文。
下面的新API用于創(chuàng)建自定義服務(wù),從依賴注入容器中返回上下文對象:
下面的代碼片段實(shí)現(xiàn)了一個(gè)自定義服務(wù),允許獲得適當(dāng)?shù)腅F 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實(shí)現(xiàn):
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附帶了新的和接口。
這些接口允許您在建立到數(shù)據(jù)庫的連接時(shí)攔截、修改和/或抑制SQL操作和命令,該列表包括低級(jí)數(shù)據(jù)庫操作,例如在會(huì)話上下文中執(zhí)行命令或設(shè)置鍵值對。一旦連接打開,您就可以在會(huì)話上下文中存儲(chǔ)值并執(zhí)行所需的請求。
設(shè)置還添加了 和 屬性,來幫助指定用于將一個(gè)事務(wù)與另一個(gè)事務(wù)隔離的隔離級(jí)別。
您可以將IsolationLevel設(shè)置為以下值當(dāng)中的一個(gè):
每次執(zhí)行查詢時(shí),將打開相應(yīng)的事務(wù)類型(None除外)。一旦請求被執(zhí)行,事務(wù)就會(huì)立即關(guān)閉。
這一策略的好處如下:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)