Dynamics CRM 2011 Linq无法在列集中指定子属性

时间:2014-01-24 22:38:29

标签: dynamics-crm-2011

var queryAccount = from r in orgServiceContext.CreateQuery("cpar")
                           select new
                           {
                               cagid = !r.Contains("cagid") ? string.Empty : r["cagid"],
                               modifiedbyname = !r.Contains("modifiedbyname") ? string.Empty : r["modifiedbyname"],
                               ownerid = !r.Contains("ownerid") ? string.Empty : r["ownerid"],
                               solutionid = !r.Contains("solutionid") ? string.Empty : r["solutionid"],
                               createdon = !r.Contains("createdon") ? string.Empty : r["createdon"],
                               subject = !r.Contains("subject") ? string.Empty : r["subject"],
                               baselineorr = !r.Contains("baseline") ? string.Empty : r["baseline"]



                           };

我收到的错误是: :+ base {" 无法在Retrieve的列集中指定子属性。属性:modifiedbyname "} System.ServiceModel.FaultException {System.ServiceModel.FaultException} 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

ModifiedByName不是实体的实际属性。您需要通过EntityReference引用该值:

var queryAccount = from r in orgServiceContext.CreateQuery("cpar")
    select new
    {
        cagid = !r.Contains("cagid") ? string.Empty : r["cagid"],
        modifiedbyname = !r.Contains("modifiedby") ? string.Empty : ((EntityReference)r["modifiedby"]).Name,
        ownerid = !r.Contains("ownerid") ? string.Empty : ((EntityReference)r["ownerid"]).Name,
        solutionid = !r.Contains("solutionid") ? string.Empty : r["solutionid"],
        createdon = !r.Contains("createdon") ? string.Empty : r["createdon"],
        subject = !r.Contains("subject") ? string.Empty : r["subject"],
        baselineorr = !r.Contains("baseline") ? string.Empty : r["baseline"]

    };