1

我继承了一些 LINQ,我想将它重写为非 LINQ C#,这样我就可以确定哪个位失败了。

(我已经订购了 ReSharper,但 JetBrains 的许可证密钥似乎很慢。)

LINQ 是

var accounts = from a in srvContext.CreateQuery<Incident>()
                join b in srvContext.CreateQuery<integ_benefitallowances>() on a.integ_BenefitId.Id equals b.integ_benefitallowancesId.Value
                where b.integ_BenefitId.Id == _currentIncident.integ_BenefitId.Id
                where a.Integ_DependantId.Id == a.Integ_DependantId.Id
                where a.integ_ClaimStatus.Value == 0 || a.integ_ClaimStatus.Value == 2
                where a.Integ_DateofClaim.Value > timePeriod
                select new Incident
                {
                     LogicalName = a.LogicalName
                };

错误是

System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: There was an error with this process
variable '<>h__TransparentIdentifier2' of type '<>f__AnonymousType0`2[PaycareCRM.Incident,PaycareCRM.integ_benefitallowances]' referenced from scope '', but it is not defined

是否有网站或简单的工具可以为我将 LINQ 转换为普通的 C#?

4

2 回答 2

4

XY 问题。

DataServiceContext 不支持 Join 或 Select(作为身份运算符除外)。

于 2013-10-02T11:49:26.557 回答
0

ReSharper 揭示了这个问题 - 一行是重言式(并且 RS 下划线突出显示了它),尽管我不明白为什么这意味着查询失败。无论如何,固定代码是

var incidents = from a in srvContext.CreateQuery<Incident>()
                join b in srvContext.CreateQuery<integ_benefitallowances>() on a.integ_BenefitId.Id equals b.integ_benefitallowancesId.Value
                where b.integ_BenefitId.Id == _currentIncident.integ_BenefitId.Id
                where a.Integ_DependantId.Id == _currentIncident.Integ_DependantId.Id
                where a.integ_ClaimStatus.Value == 0 || a.integ_ClaimStatus.Value == 2
                where a.Integ_DateofClaim.Value > timePeriod
                select new Incident
                        {
                                LogicalName = a.LogicalName
                        };
于 2013-10-02T14:28:40.977 回答