Linq where子句无效

时间:2016-05-10 17:13:22

标签: linq dynamics-crm crm

                var advocacy = (from c in svcContext.CreateQuery("lead")
                           join a in svcContext.CreateQuery("product")
                           on c["transactioncurrencyid"] equals a["transactioncurrencyid"]
                           where a["capg_billingtimeframe"].Equals(126350000)


                           select new
                           {
                               dues = c["capg_calculatedduesbilling"],
                               product = c["capg_primaryproduct"],
                               listprice = a["price"],
                               eligibility = c.FormattedValues["capg_eligibility"]
                           });

这是我的linq查询,它给了我错误:无效'其中'条件。实体成员正在调用无效的属性或方法。

我到处看都在线,并完成了他们的建议。我没有使用Xrm.cs,因为后期绑定可以更快。我尝试过使用==操作数,我尝试过(int)和Convert.ToInt32([" capg_billingtimeframe"]),甚至将所有内容转换为字符串。我会说[" capg_billingtimeframe"]我知道这是一个对象(这就是我进行转换的原因。

2 个答案:

答案 0 :(得分:0)

我猜这个整数,capg_billingtimeframe是一个选项集。如果是,你需要像这样投射:

where ((OptionSetValue)a["capg_billingtimeframe"]).Value == 126350000

答案 1 :(得分:0)

我使用早期绑定并获取当地我写道:

OptionSetValue branch = this.InputTargetEntity.Attributes.Contains("capg_calculatorutilized") ? (OptionSetValue)this.InputTargetEntity["capg_calculatorutilized"] : (OptionSetValue)this.TargetPreImage["capg_calculatorutilized"];

然后我必须使用crmsvcutil并编写:

来获取Optionsets.cs
if (branch.Value == (int)capg_calculatorrequired.SectionA)

像魅力一样。

相关问题