我有跟踪 linq 到实体查询,它看起来很适合编译,但是在我运行代码时给了我以下错误。我想得到一个非常复杂的对象,它有一些来自 EDM 模型的派生对象列表。下面类中的列表不是直接来自 EDM 模型,而是来自 EDM 的派生类,为我的问题增加了更多复杂性。这是错误消息。请帮助我解决此查询。我必须在一个 linq 查询中获取我想要的所有数据,这就是我的领导之前要求我的,我对每个组件都有一个查询,我正在添加它们。但铅希望它在一个查询中。请以任何方式帮助我链接或代码片段或任何建议。
LINQ to Entities 无法识别方法 'System.Collections.Generic.List`1[LNI.WSAW.External.StayAtWork.EmployerAddress] ToList[EmployerAddress](System.Collections.Generic.IEnumerable`1[LNI.WSAW.External. StayAtWork.EmployerAddress])' 方法,并且该方法不能转换为商店表达式。
这是代码:
Dim _requestrecord = (From r In Context.Requests.Include("Claims").Include("Employers").Include("EmployerContacts") 其中 r.RequestId = RequestId AndAlso r.ManualClaimFlag = ManualClaim 在 Context.Claims 中加入 c r.ClaimId 等于 c.ClaimId where c.ClaimNo.Equals(ClaimNumber) 在 r.Employer.EmployerId 上的 Context.Employers 中加入 e 等于 e.EmployerId 其中 e.EmplAccntNo.Equals(EmployerAccountNumber) 在 r.EmployerContactId 上加入 ec.EmployerContacts 等于 ec.EmployerContactId 其中 ec.SawGuid.Equals(EmployerContactGuid) 使用 { _ 选择新的 RequestRecord() .Addresses =(来自在 Context.EmployerAddressTypes 在 Context.EmployerAddresses 中加入 ea 在 at.AddressTypeId 等于 ea.EmployerAddressType.AddressTypeId 其中 ea.EmployerId = r.Employer.EmployerId 选择带有 { _ 的新 External.StayAtWork.EmployerAddress() .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 = (来自 td In Context.TransactionDates 其中 td.RequestId = RequestId 在 Context.ExpenseTransactions 中加入 ex.TransactionDateId 等于 td.TransactionDateId 选择 New External.StayAtWork.RequestExpense() With { _ .ExpenseAmount = ex.ExpenseAmount, .ExpenseDate = ex.TransactionDate.TransactionDt.ToString(), .ExpenseItem = ex.ExpenseItem, .ExpenseReason = ex.ExpenseReason, .ExpenseType = ex.ExpenseSubTypeId }).ToList(), .Wages = (来自 td In Context.TransactionDates 其中 td.RequestId = RequestId 加入 wt 在 Context.WageTransactions On wt.TransactionDateId 等于 td.TransactionDateId 选择带有 { _ 的新 External.StayAtWork.RequestWage() .DailyWage = wt.DailyWagePaidAmount, .WorkDate = wt.TransactionDate.TransactionDt.ToString(), .WorkHours = wt.WorkHours.ToString() }).ToList(), .Timeloss = (来自 ctl In Context.ClaimTimelosses 加入 clms 在 Context.Claims On ctl.ClaimId 等于 clms.ClaimId 其中 clms.ClaimId = c.ClaimId 选择 New External.StayAtWork.ClaimTimeLoss() With { _ .ClaimNo = ctl.Claim.ClaimNo, .FromDate = ctl.FromDt.ToString(), .ToDate = ctl.ToDt.ToString() }).ToList(), .Files =(来自 Context.RequestFiles 中的 rfs 在 rfs.RequestId 上的 Context.Requests 中加入 reqs 等于 reqs.RequestId 其中 reqs.RequestId = RequestId 选择带有 { _ 的新 FileBasic() .FileId = rfs.RequestFileId, .FileName = rfs.FileName, .FromDiv = rfs.FromDiv }).ToList(), .UiSettings = (来自 ruis In Context.RequestUis 在 ruis.RequestId 上加入 Context.Requests 中的 reqs 等于 reqs.RequestId 其中 reqs.RequestId = RequestId 选择 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
这是我必须上的课程: 公共类请求记录
<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