当我调用“列出异步方法”时,我有三个可查询的项目,我在 EF core 中遇到以下错误

问题描述 投票:0回答:1

您好,我从存储库中获取了三个查询,并在应用程序层中将查询转换为列表。 下面是我的代码:

private async Task<Tuple<List<GetCustomerDto>, List<GetSarfaslDto>, List<GetCusTellDto>>> getQuery()
    {
        try
        {
            var customersTask =await _customerRepository.GetCustomers().ToListAsync().ConfigureAwait(false);

            var sarfaslsTask = await _customerRepository.GetCustomerSarfasl().ToListAsync().ConfigureAwait(false);

            var cusTellsTask = await _cusTellRepository.GetCusTell().ToListAsync().ConfigureAwait(false);

            return new Tuple<
                List<GetCustomerDto>,
                List<GetSarfaslDto>,
                List<GetCusTellDto>>( customersTask,  sarfaslsTask,  cusTellsTask);
        }
        catch (Exception ex)
        {
            throw;
        }
    }

但我收到以下错误: “BeginExecuteReader 需要一个打开且可用的连接。连接的当前状态已关闭。”}

下面是我的存储库查询:

public class CustomerRepository : ICustomerRepository
{
    #region Feilds
    private readonly HolooDatabaseContext _context;

    #endregion

    public CustomerRepository(HolooDatabaseContext context)
    {
        _context = context;
    }

    public IQueryable<GetSarfaslDto> GetCustomerSarfasl()
    {
        var query = (from customer in _context.CUSTOMER
                     join sarfasl in _context.SARFASL on customer.C_Code.Substring(RepositoryConstants.C_CODE) equals sarfasl.Sarfasl_Code.Substring(RepositoryConstants.SARFASL_C_CODE)
                     where sarfasl.Col_Code.Equals(RepositoryConstants.SARFASL_CODE)
                     select new GetSarfaslDto()
                     {
                         Sarfasl_Name = sarfasl.Sarfasl_Name,
                         Common = sarfasl.Common,
                         Col_Code = sarfasl.Col_Code,
                         Moien_Code = sarfasl.Moien_Code,
                         Tafzili_Code = sarfasl.Tafzili_Code,
                         Sarfasl_Code = sarfasl.Sarfasl_Code,
                         Group = sarfasl.Group,
                         Mahiat = sarfasl.Mahiat,
                         Can_Delete = sarfasl.Can_Delete,
                         Parent = sarfasl.Parent,
                         Type = sarfasl.Type,
                         ArzId = sarfasl.ArzId,
                         AutoUse = sarfasl.AutoUse,
                         DefaultSarfasl_Code = sarfasl.DefaultSarfasl_Code,
                         Delete = sarfasl.Delete,
                         ID = sarfasl.ID,
                         Mandeh = sarfasl.Mandeh,
                         MHaz_Code = sarfasl.MHaz_Code,
                         Money_Price = sarfasl.Money_Price,
                         OldType = sarfasl.OldType,
                         Sarfasl_Codeold = sarfasl.Sarfasl_Codeold,
                         Selected = sarfasl.Selected,
                         SParent = sarfasl.SParent,
                     }).AsQueryable();

        return query;
    }

    public IQueryable<GetCustomerDto> GetCustomers()
    {
        var query = (from customer in _context.CUSTOMER
                     join bedBesView in _context.W0_Calc_BedBes_UseInView on customer.C_Code equals bedBesView.CCode into bdc
                     from bd in bdc.DefaultIfEmpty()

                     let ff = _context.FACTURE.DefaultIfEmpty()
                         .FirstOrDefault(f => f.C_Code == customer.C_Code && f.Fac_Type == RepositoryConstants.FAC_TYPE_F)

                     let fk = _context.FACTURE.DefaultIfEmpty()
                         .FirstOrDefault(f => f.C_Code == customer.C_Code && f.Fac_Type == RepositoryConstants.FAC_TYPE_K)

                     let vastehCount = _context.CustomerVaseteh.Count(c => c.C_Code == customer.C_Code)

                     select new GetCustomerDto()
                     {
                         C_Code = customer.C_Code,
                         C_Code_C = customer.C_Code_C,
                         C_Name = customer.C_Name,
                         Kharid = customer.Kharid,
                         Forosh = customer.Forosh,
                         Vaseteh = customer.Vaseteh,
                         Vaseteh_Porsant = customer.Vaseteh_Porsant,
                         Karshenas = customer.Karshenas,
                         InListSiah = customer.InListSiah,
                         SelectType = customer.SelectType,
                         City_Code = customer.City_Code,
                         First_BalanceSanad = customer.First_BalanceSanad,
                         Sum_Takhfif = customer.Sum_Takhfif,
                         Etebar = customer.Etebar,
                         NetHlp = customer.NetHlp,
                         Col_Code_Bed = customer.Col_Code_Bed,
                         Moien_Code_Bed = customer.Moien_Code_Bed,
                         ArzID = customer.ArzID,
                         money_price = customer.money_price,
                         CalledDate = customer.CalledDate,
                         Creation_Date = customer.Creation_Date,
                         National_Code = customer.National_Code,
                         Economic_Code = customer.Economic_Code,
                         C_Tel = customer.C_Tel,
                         C_Mobile = customer.C_Mobile,
                         C_Fax = customer.C_Fax,
                         Cust_City = customer.Cust_City,
                         Cust_Ostan = customer.Cust_Ostan,
                         Cust_Mantagheh = customer.Cust_Mantagheh,
                         Zip_Code = customer.Zip_Code,
                         C_Address = customer.C_Address,
                         Email_Address = customer.Email_Address,
                         WebId = customer.WebId,
                         C_type = customer.C_type,
                         IsSeller = customer.IsSeller,
                         Cust_type = customer.Cust_type,
                         Agent = customer.Agent,
                         Agent_Porsant = customer.Agent_Porsant,
                         Anbardar = customer.Anbardar,
                         Arayeshgar = customer.Arayeshgar,
                         Arayesh_Porsant = customer.Arayesh_Porsant,
                         Arz_Mandeh = customer.Arz_Mandeh,
                         AwardCustomer = customer.AwardCustomer,
                         Birth_Date = customer.Birth_Date,
                         CAlarmEtebarCheck = customer.CAlarmEtebarCheck,
                         Car_Id = customer.Car_Id,
                         CheckReciveOfEtebar = customer.CheckReciveOfEtebar,
                         Choice = customer.Choice,
                         CityCodeLevy = customer.CityCodeLevy,
                         Cobbler = customer.Cobbler,
                         Col_Code_Bes = customer.Col_Code_Bes,
                         Comment = customer.Comment,
                         Companey_Code_F = customer.Companey_Code_F,
                         CoName = customer.CoName,
                         ContactDate = customer.ContactDate,
                         Counective_Name = customer.Counective_Name,
                         Counective_Tel = customer.Counective_Tel,
                         Cust_Job = customer.Cust_Job,
                         Cutter = customer.Cutter,
                         C_AliasName = customer.C_AliasName,
                         C_Code_C2 = customer.C_Code_C2,
                         DarsadAmuzeshP = customer.DarsadAmuzeshP,
                         DarsadEconomicCode = customer.DarsadEconomicCode,
                         DarsadShahrdari = customer.DarsadShahrdari,
                         Delete = customer.Delete,
                         DressType = customer.DressType,
                         Driver = customer.Driver,
                         Endeditdate = customer.Endeditdate,
                         Etebargerami = customer.Etebargerami,
                         ExporterSId = customer.ExporterSId,
                         FactOutOfEtebar = customer.FactOutOfEtebar,
                         First_BalanceSanad_Bes = customer.First_BalanceSanad_Bes,
                         Gender = customer.Gender,
                         GroupId = customer.GroupId,
                         HkharidarType1code = customer.HkharidarType1code,
                         HlpAman = customer.HlpAman,
                         Zone = customer.Zone,
                         isAbkar = customer.isAbkar,
                         isAbKonandeh = customer.isAbKonandeh,
                         IsActive = customer.IsActive,
                         isBonakdar = customer.isBonakdar,
                         IsChange = customer.IsChange,
                         IsCMS = customer.IsCMS,
                         isFactory = customer.isFactory,
                         isGoldmaker = customer.isGoldmaker,
                         isHamkar = customer.isHamkar,
                         iskifi = customer.iskifi,
                         isMekhrajiKargah = customer.isMekhrajiKargah,
                         isOtherCust = customer.isOtherCust,
                         isReygir = customer.isReygir,
                         isReygirKargah = customer.isReygirKargah,
                         isShopper = customer.isShopper,
                         isTamirKar = customer.isTamirKar,
                         JavaherSaz = customer.JavaherSaz,
                         KarPorsant = customer.KarPorsant,
                         KarPorsantDarsad = customer.KarPorsant,
                         KarPorsantType = customer.KarPorsantType,
                         latitude = customer.latitude,
                         longitude = customer.longitude,
                         Mandehgold750 = customer.Mandehgold750,
                         MandehPelatin = customer.MandehPelatin,
                         Mekhrajkar = customer.Mekhrajkar,
                         Mercer = customer.Mercer,
                         ModifyDate = customer.ModifyDate,
                         MohlatTasvieh = customer.MohlatTasvieh,
                         Moien_Code_Bes = customer.Moien_Code_Bes,
                         National_Code_F = customer.National_Code_F,
                         Notionality = customer.Notionality,
                         OstanCodeLevy = customer.OstanCodeLevy,
                         PelakChar = customer.PelakChar,
                         PelakCity = customer.PelakCity,
                         Pelakcitycode = customer.Pelakcitycode,
                         Pelakcode2 = customer.Pelakcode2,
                         Pelakcode3 = customer.Pelakcode3,
                         Personal_Code_F = customer.Personal_Code_F,
                         Personel = customer.Personel,
                         Porsant = customer.Porsant,
                         Porsant2 = customer.Porsant2,
                         PriceHamkar = customer.PriceHamkar,
                         Res_cust = customer.Res_cust,
                         SanadOutOfEtebar = customer.SanadOutOfEtebar,
                         SarFasl_Amani_Dar = customer.SarFasl_Amani_Dar,
                         SarFasl_Amani_Par = customer.SarFasl_Amani_Par,
                         SenfId = customer.SenfId,
                         SMSGroup = customer.SMSGroup,
                         Tafzili_Code_Bed = customer.Tafzili_Code_Bed,
                         Tafzili_Code_Bes = customer.Tafzili_Code_Bes,
                         Tailor = customer.Tailor,
                         TasviehType = customer.TasviehType,
                         TimeEndCustArayesh = customer.TimeEndCustArayesh,
                         TimeStartCustArayesh = customer.TimeStartCustArayesh,
                         UserCodeCust = customer.UserCodeCust,
                         Vaseteh_Code = customer.Vaseteh_Code,
                         Vaseteh_Porsant_C = customer.Vaseteh_Porsant_C,
                     }).AsQueryable();

        return query;
    }
}

由于性能原因,我需要异步运行它们。

有人可以帮忙吗?

entity-framework task
1个回答
0
投票

终于找到问题所在了。我没有在端点层使用await,所以我得到了这个异常。

公共异步任务执行(IJobExecutionContext 上下文) { 等待 _mediator.Send(new GetCustomerDataTransferQuery(), CancellationToken.None); }

© www.soinside.com 2019 - 2024. All rights reserved.