我有跟随linq到实体查询,它看起来很适合编译,但在运行代码时给我以下错误。我想得到一个非常复杂的对象,它有一些来自EDM模型的派生对象列表。下面的类中的列表不是直接来自EDM模型,而是来自EDM的派生类,以增加我的问题的复杂性。这是错误消息。请帮我解决这个问题。我必须在一个linq查询中获取我想要的所有数据,这是我的主管先前要求我的,每个组件都有一个查询,我正在添加它们。但是铅在一个查询中想要它。请以任何方式帮助我链接或代码片段或任何建议。
LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[LNI.WSAW.External.StayAtWork.EmployerAddress] ToList[EmployerAddress](System.Collections.Generic.IEnumerable`1[LNI.WSAW.External.StayAtWork.EmployerAddress])' method, and this method cannot be translated into a store expression.
以下是代码:
Dim _requestrecord = (From r In Context.Requests.Include("Claims").Include("Employers").Include("EmployerContacts") Where r.RequestId = RequestId AndAlso r.ManualClaimFlag = ManualClaim Join c In Context.Claims On r.ClaimId Equals c.ClaimId Where c.ClaimNo.Equals(ClaimNumber) Join e In Context.Employers On r.Employer.EmployerId Equals e.EmployerId Where e.EmplAccntNo.Equals(EmployerAccountNumber) Join ec In Context.EmployerContacts On r.EmployerContactId Equals ec.EmployerContactId Where ec.SawGuid.Equals(EmployerContactGuid) Select New RequestRecord() With { _ .Addresses = (From at In Context.EmployerAddressTypes Join ea In Context.EmployerAddresses On at.AddressTypeId Equals ea.EmployerAddressType.AddressTypeId Where ea.EmployerId = r.Employer.EmployerId Select New External.StayAtWork.EmployerAddress() With { _ .AddressLn1 = ea.AddressLn1, .AddressLn2 = ea.AddressLn2, .AddressLn3 = ea.AddressLn3, .AddressType = at.Description, .BusLocAddressId = ea.BuslocId, .City = ea.City, .Country = ea.Country, .NewSwAddress = ea.NewSwAddressFlag, .State = ea.St, .Zip = ea.Zip, .ZipExt = ea.ZipExt }).ToList(), .Employer = New EmployerBaisc() With { _ .EmployerId = e.EmployerId, .EmployerName = e.EmplName }, .Exspenses = (From td In Context.TransactionDates Where td.RequestId = RequestId Join ex In Context.ExpenseTransactions On ex.TransactionDateId Equals td.TransactionDateId Select New External.StayAtWork.RequestExpense() With { _ .ExpenseAmount = ex.ExpenseAmount, .ExpenseDate = ex.TransactionDate.TransactionDt.ToString(), .ExpenseItem = ex.ExpenseItem, .ExpenseReason = ex.ExpenseReason, .ExpenseType = ex.ExpenseSubTypeId }).ToList(), .Wages = (From td In Context.TransactionDates Where td.RequestId = RequestId Join wt In Context.WageTransactions On wt.TransactionDateId Equals td.TransactionDateId Select New External.StayAtWork.RequestWage() With { _ .DailyWage = wt.DailyWagePaidAmount, .WorkDate = wt.TransactionDate.TransactionDt.ToString(), .WorkHours = wt.WorkHours.ToString() }).ToList(), .Timeloss = (From ctl In Context.ClaimTimelosses Join clms In Context.Claims On ctl.ClaimId Equals clms.ClaimId Where clms.ClaimId = c.ClaimId Select New External.StayAtWork.ClaimTimeLoss() With { _ .ClaimNo = ctl.Claim.ClaimNo, .FromDate = ctl.FromDt.ToString(), .ToDate = ctl.ToDt.ToString() }).ToList(), .Files = (From rfs In Context.RequestFiles Join reqs In Context.Requests On rfs.RequestId Equals reqs.RequestId Where reqs.RequestId = RequestId Select New FileBasic() With { _ .FileId = rfs.RequestFileId, .FileName = rfs.FileName, .FromDiv = rfs.FromDiv }).ToList(), .UiSettings = (From ruis In Context.RequestUis Join reqs In Context.Requests On ruis.RequestId Equals reqs.RequestId Where reqs.RequestId = RequestId Select New External.StayAtWork.RequestUI() With { _ .ApfByFax = ruis.ApfByFaxFlag, .ApfByMail = ruis.ApfByMailFlag, .ApfLniHas = ruis.ApfLniHasFlag, .ExpenseByFax = ruis.ExpenseByFaxFlag, .ExpenseByMail = ruis.ExpenseByMailFlag, .ExpenseLniHas = ruis.ExpenseLniHasFlag, .JobByFax = ruis.JobByFaxFlag, .JobByLni = ruis.JobByLniFlag, .JobByMail = ruis.JobByMailFlag, .LastDiv = ruis.LastDiv, .requestId = ruis.RequestId, .WageByFax = ruis.WageByFaxFlag, .WageByMail = ruis.WageByMailFlag, .WageLniHas = ruis.WageLniHasFlag }).FirstOrDefault(), .Request = New RequestBasic() With { _ .RequestId = RequestId, .Comments = r.Comments, .InjuredWorkerName = c.WorkerName, .IsFixedSalary = r.FixedSalaryFlag, .IsGraveyard = r.GraveyardFlag, .IsManualClaim = r.ManualClaimFlag, .JobDescriptBeforeInjury = r.JobDescriptBefore, .JobDescriptLightDuty = r.JobDescriptLightduty, .TrackHoursFlag = r.HoursTrackedFlag } }).FirstOrDefault()在此先感谢。Response.ResultData = _requestrecord
And here is the the class that I have to get: Public Class RequestRecord
<DataMember()> Public Property Request As RequestBasic <DataMember()> Public Property Employer As EmployerBaisc <DataMember()> Public Property Addresses As List(Of EmployerAddress) <DataMember()> Public Property Timeloss As List(Of ClaimTimeLoss) <DataMember()> Public Property Wages As List(Of RequestWage) <DataMember()> Public Property Exspenses As List(Of RequestExpense) <DataMember()> Public Property Files As List(Of FileBasic) <DataMember()> Public Property PaidDates As List(Of PaidDate) <DataMember()> Public Property UiSettings As RequestUI End Class