Royi Namir
Royi Namir

Reputation: 148524

Linq -Where clause with not exists?

I have a list of list of Policies.

I Also have a external datatable which has a DecisionId column ( among other columns as well).

I need to find all policies which their IsUWDecsionApproved prop is false

and

The policy property which is called DecisionId should not exists in the datatable. ( at the DecisionId column).

here is my try :

var t = _chached.SelectMany(f => f.LST_Policy)
                .Where(fd =>!fd.IsUWDecsionApproved &&
                            !(dt.AsEnumerable() .Select(b => b["DecisionId"].ToString()))
                            .Contains(fd => fd.UWdecisionID)
                      );

Here is the error : https://i.sstatic.net/Y1QNE.png

enter image description here

Sql wording :

select policy from _cached where !policy.IsUWDecsionApproved && policy.DecisionIdId not in
 ( select DecisionIdId from datatable)

How can I fix that ? ( no temp Ienumerables please)

Visual :

I need that second fd will be the same as the first fd :

enter image description here

edit :

https://i.sstatic.net/syMgY.png enter image description here

Upvotes: 0

Views: 152

Answers (1)

Arun Aravind
Arun Aravind

Reputation: 1318

Change ->

ie Contains(fd.UWdecisionID).

The error here was you defined fd in the where clause delegate parameter and tried to reuse the same name in the Contains clause which comes inside the Where clause.

That is why the compiler complained.

Upvotes: 2

Related Questions