Linq where the definition of a sentence for an attribute on the wrong object

Hi, I have the following Linq request:

(from c in new_contactsubscriptionSet join p in new_PaymentStatusSet on c.new_PaymentStatusId.Id equals p.new_PaymentStatusId where (c.new_EndDate > DateTime.Now && c.new_EndDate <= DateTime.Now.AddDays(14)) && p.new_IsPaidStatus == false select c) 

It throws the following FaultException , which means its check attribute is new_ispaidstatus on the wrong object. It should check new_PaymentStatus , not new_contactsubscription

Faultexception

'new_contactsubscription' entity doesn't contain attribute with Name = 'new_ispaidstatus'.

If I use the following queries, it works fine:

 (from c in new_contactsubscriptionSet join p in new_PaymentStatusSet on c.new_PaymentStatusId.Id equals p.new_PaymentStatusId where p.new_IsPaidStatus == false select c) 

OR

 (from c in new_contactsubscriptionSet join p in new_PaymentStatusSet on c.new_PaymentStatusId.Id equals p.new_PaymentStatusId where (c.new_EndDate > DateTime.Now && c.new_EndDate <= DateTime.Now.AddDays(14)) select c) 

There seems to be something wrong with the Where clause. Can someone help me fix this query.

Thanks at Advance

+4
source share
1 answer

You will need a different place for each object.

 (from c in new_contactsubscriptionSet join p in new_PaymentStatusSet on c.new_PaymentStatusId.Id equals p.new_PaymentStatusId where (c.new_EndDate > DateTime.Now && c.new_EndDate <= DateTime.Now.AddDays(14)) where p.new_IsPaidStatus == false select c) 

This is due to how Microsoft maps the Linq query to the query expression. He is trying to match somewhere only the filter criteria, but they are applied based on the entity to the entity. Therefore, it determines the names of all the attributes used and creates a filter for it against the first expression, which it evaluates to "entity".

When using the plural, it will update the filter of the second Related entity, and not blindly add it to the first.

+7
source

Source: https://habr.com/ru/post/1502609/


All Articles