LINQ中的Where语句中的错误 [英] Error within Where statement in LINQ

查看:95
本文介绍了LINQ中的Where语句中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我说机会实体中不存在名字".但这是为SystemUser实体设置的.知道为什么会感到困惑吗?谢谢!

For some reason in my where it says that "firstname" does not exist in the Opportunity Entity. But it is set for the SystemUser Entity. Any idea why it is getting confused? Thanks!

            var linqQuery = (from r in gServiceContext.CreateQuery("opportunity")
                             join c in gServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals c["accountid"]
                             join u in gServiceContext.CreateQuery("systemuser") on ((EntityReference)r["ownerid"]).Id equals u["systemuserid"]
                             where r["new_leadstatus"].Equals("100000004") && u["lastname"].Equals(rsmLastName) && u["firstname"].Equals(rsmFirstName)
                             select new
                             {
                                 AccountId = !r.Contains("accountid") ? string.Empty : r["accountid"],
                                 Account = !r.Contains("name") ? string.Empty : r["name"]
                             });

推荐答案

确保将每个where子句放在其自己的行中

Make sure you put each where clause in its own line per Microsoft guidelines.

where 子句通常对结果应用过滤器 布尔表达式.过滤器指定要排除的元素 从源序列开始.每个 where 子句只能包含 针对单个实体类型的条件.复合条件 涉及多个实体无效.相反,每个实体都应 在单独的 where 子句中进行过滤.

The where clause applies a filter to the results, often using a Boolean expression. The filter specifies which elements to exclude from the source sequence. Each where clause can only contain conditions against a single entity type. A composite condition involving multiple entities is not valid. Instead, each entity should be filtered in separate where clauses.

var linqQuery = from r in gServiceContext.CreateQuery("opportunity")
                join c in gServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals c["accountid"]
                join u in gServiceContext.CreateQuery("systemuser") on ((EntityReference)r["ownerid"]).Id equals u["systemuserid"]
                where r["new_leadstatus"].Equals("100000004")
                where u["lastname"].Equals(rsmLastName) && u["firstname"].Equals(rsmFirstName)
                select new
                {
                    AccountId = !r.Contains("accountid") ? string.Empty : r["accountid"],
                    Account = !r.Contains("name") ? string.Empty : r["name"]
                };

这篇关于LINQ中的Where语句中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆