Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

Linq Query Failing - "'Contact' entity doesn't contain attribute with Name = ."

$
0
0

Start

I ran across a linq error today where by a seemling straightforward linq query failed.

The query in question was on customised entities, however I have recreated the same error using the OTB account and contact entities.

The query below fails with the error "'Contact' entity doesn't contain attribute with Name = 'parentaccountid'."

            using (var ctx = new OrganizationServiceContext (_serviceProxy))            {                var accounts = (from a in ctx.CreateQuery<Account>()                           join c in ctx.CreateQuery<Contact>()                               on a.AccountId equals c.AccountId.Id                           where c.BirthDate == null                                && a.ParentAccountId != null                           select c                    ).ToList();            }

Interesting enough - this query fails with the error: "'Account' entity doesn't contain attribute with Name = 'birthdate'."

(I just swapped the order of the parameters in the where clause)

            using (var ctx = new OrganizationServiceContext (_serviceProxy))            {                var accounts = (from a in ctx.CreateQuery<Account>()                           join c in ctx.CreateQuery<Contact>()                               on a.AccountId equals c.AccountId.Id                           where a.ParentAccountId != null                                && c.BirthDate == null                           select c                    ).ToList();            }

Finally the query works where I only include one of the filters in the where clause - it doesnt matter which one is included.

This only seems to occur where one of the parameters is an entity reference - if i changed the filter from ParentAccountId to AccountName it works fine.

As far as I am aware there is no valid reason for this query failing - I would imagine that it would work if I were to manually build the QueryExpression in the old CRM 4 manner - I am wondering if I am missing something obvious?


Viewing all articles
Browse latest Browse all 1000


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>