gpt4 book ai didi

c# Entity Framework 为每个方法打开和关闭dbcontext实例

转载 作者:太空宇宙 更新时间:2023-11-03 23:02:47 25 4
gpt4 key购买 nike

<分区>

  1. 更新 dbcontext 的实例化是“不好的”,如果是这样,我能做些什么不同的事情?
  2. 关于此方法的静态坏主意?

网络接口(interface)

public IEnumerable<GetUtilityPrograms_Result> GetUtilityPrograms(int vendorid, int officeid, string state,string zip)
{
var utilityPrograms = Business.AppLogic.GetUtilityPrograms(vendorid, officeid, state, zip);
return utilityPrograms;
}

业务逻辑

    public static List<GetVerifiedChartDetail_Result> GetVerifiedChartDetailData(DateTime sDate, int vendorId, int officeId)
{
List<GetVerifiedChartDetail_Result> verifiedChart;
int? v = (vendorId == 0 ? new int?() : vendorId);
int? o = (officeId == 0 ? new int?() : officeId);
using (CustomSparkPortalDataEntities ctx = new CustomSparkPortalDataEntities())
{
verifiedChart = ctx.GetVerifiedChartDetail(sDate, v, o).ToList();
}
return verifiedChart;
}

public static List<GetVerifiedAccountsChartSummary_Result> GetVerifiedAccountsChartData(DateTime sDate, int vendorId, int officeId)
{
List<GetVerifiedAccountsChartSummary_Result> verifiedChart;
int? v = (vendorId == 0 ? new int?() : vendorId);
int? o = (officeId == 0 ? new int?() : officeId);
using (CustomSparkPortalDataEntities ctx = new CustomSparkPortalDataEntities())
{
verifiedChart = ctx.GetVerifiedAccountsChartSummary(sDate, v, o).ToList();
}
return verifiedChart;
}

调用数据实体

   public CustomSparkPortalDataEntities()
: base()
{
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com