.net - Any() is not returning expected result -- alternatives? -


edit2 found solution team members. see comment resolution.

after looking, can't seem find real answer problem.

i'm trying find users have groups group type blank/null/empty. code:

expression = (x => x.persongroups.any(y => y.group.grouptype == null || y.group.grouptype == ""));  return expression 

there many users in our database expression should return. instead, doesn't return any. colleague smarter , more experienced me looked @ generated sql me yesterday, , concluded wonderful example of linq , entity not working together. entity on querying mapped database. i've checked , checked, , piece of code code doing (not before or after). befuddling there other linq queries in our code similar 1 return expected result.

so 2 questions:

1) there see doing wrong?

2) without writing raw sql, possible alternatives be? i've been trying read linq can, i'm sure i'm missing something.

thanks!

(note: haven't found these posts quite answer questions: 1, 2, 3, 4)

edit1: generated sql code.

select  [unionall4].[c2] [c1],  [unionall4].[c218] [c218]  (select      [unionall3].[c1] [c1],      [unionall3].[c2] [c2],      [unionall3].[c193] [c218]      (select          case when ([unionall1].[person1id1] null) cast(null int) else 1 end [c1],          [project6].[c1] [c2],           cast(null bit) [c193]           (select              [project4].[id] [id],              [project4].[profilepicturepath] [profilepicturepath],              1 [c1]             ( select                  [extent1].[id] [id],                   [extent1].[profilepicturepath] [profilepicturepath],                  (select                      count(1) [a1]                     [dbo].[ppeople_disciplines] [extent4]                     [extent1].[id] = [extent4].[people_id]) [c1]                 [dbo].[person] [extent1]                 ( exists (select                      1 [c1]                     ( select                          [extent2].[id] [id],                          [extent2].[discipline] [discipline]                         [dbo].[ppeople_disciplines] [extent2]                         [extent1].[id] = [extent2].[people_id]                     )  [project1]                     (ltrim(rtrim([project1].[discipline])) in (n'rr', n'iar', n'ins', n'tax', n'trst', n'mrtg', n'bd', n'ria')) , (ltrim(rtrim([project1].[discipline])) not null) , ((@p__linq__0 = 1) or (@p__linq__1 = 1) or ( exists (select                          1 [c1]                         [dbo].[ppeople_discipline_agents] [extent3]                         ([project1].[id] = [extent3].[people_discipline_id]) , ([extent3].[agent_id] in (cast(5307 bigint), cast(241 bigint), cast(242 bigint), cast(271 bigint), cast(274 bigint), cast(275 bigint), cast(276 bigint), cast(373 bigint), cast(543 bigint), cast(754 bigint), cast(760 bigint), cast(761 bigint), cast(793 bigint), cast(794 bigint), cast(795 bigint), cast(796 bigint), cast(832 bigint), cast(833 bigint), cast(834 bigint), cast(938 bigint), cast(1370 bigint), cast(1580 bigint), cast(1733 bigint), cast(1809 bigint), cast(1857 bigint), cast(1903 bigint), cast(1951 bigint), cast(2265 bigint), cast(2391 bigint), cast(2397 bigint), cast(2423 bigint), cast(2556 bigint), cast(2567 bigint), cast(2581 bigint), cast(2743 bigint), cast(2744 bigint), cast(2745 bigint), cast(2819 bigint), cast(3153 bigint), cast(3162 bigint), cast(3166 bigint), cast(3212 bigint), cast(3227 bigint), cast(3398 bigint), cast(3634 bigint), cast(3722 bigint), cast(3757 bigint), cast(3820 bigint), cast(3862 bigint), cast(3871 bigint), cast(4393 bigint), cast(4461 bigint), cast(4565 bigint), cast(4592 bigint), cast(4742 bigint), cast(4955 bigint), cast(5002 bigint), cast(5104 bigint), cast(5234 bigint), cast(5254 bigint), cast(5306 bigint), cast(5321 bigint), cast(5322 bigint)))                     )))                 )) , ([extent1].[holdingcompanyid] = @p__linq__2) , ([extent1].[confirmationneededtypeid] null)             )  [project4]             ( exists (select                  1 [c1]                  [dbo].[ppeople_groups] [extent5]                 inner join [dbo].[groups] [extent6] on [extent5].[group_id] = [extent6].[id]                 ([project4].[id] = [extent5].[people_id]) , ((len([extent6].[group_type])) = 0)             )) , (1 =  cast( [project4].[personstatustypeid] int)) , ([project4].[isdeleted] <> cast(1 bit)) , ([project4].[c1] > 0) ) [project6]         outer apply  (select              case when ([extent11].[id] null) cast(null int) else 1 end [c1],              [extent8].[person1id] [person1id],              cast(null varchar(1)) [c11]                 [dbo].[personrelationship] [extent7]             left outer join [dbo].[personrelationshipmarriagedetail] [extent8] on ([extent7].[relationshiptypeid] = [extent8].[relationshiptypeid]) , ([extent7].[person2id] = [extent8].[person2id]) , ([extent7].[person1id] = [extent8].[person1id])             inner join [dbo].[person] [extent9] on [extent7].[person1id] = [extent9].[id]             inner join [dbo].[person] [extent10] on [extent7].[person2id] = [extent10].[id]             left outer join [dbo].[ppeople_disciplines] [extent11] on [extent11].[people_id] = [extent7].[person1id]             [project6].[id] = [extent7].[person1id]         union             select              2 [c1],              [extent13].[person1id] [person1id],               [extent16].[level] [level]                 [dbo].[personrelationship] [extent12]             left outer join [dbo].[personrelationshipmarriagedetail] [extent13] on ([extent12].[relationshiptypeid] = [extent13].[relationshiptypeid]) , ([extent12].[person2id] = [extent13].[person2id]) , ([extent12].[person1id] = [extent13].[person1id])             inner join [dbo].[person] [extent14] on [extent12].[person1id] = [extent14].[id]             inner join [dbo].[person] [extent15] on [extent12].[person2id] = [extent15].[id]             inner join [dbo].[ppeople_disciplines] [extent16] on ([extent12].[person2id] = [extent15].[id]) , ([extent16].[people_id] = [extent15].[id])             [project6].[id] = [extent12].[person1id]) [unionall1]     union         select          2 [c1],          [project15].[c1] [c2],          cast(null varchar(1)) [c192],          cast(null bit) [c193]           (select              [project13].[id] [id],               [project13].[profilepicturepath] [profilepicturepath],              1 [c1]             ( select                  [extent17].[id] [id],                  [extent17].[profilepicturepath] [profilepicturepath],                  (select                      count(1) [a1]                     [dbo].[ppeople_disciplines] [extent20]                     [extent17].[id] = [extent20].[people_id]) [c1]                 [dbo].[person] [extent17]                 ( exists (select                      1 [c1]                     ( select                          [extent18].[id] [id],                          [extent18].[discipline] [discipline]                         [dbo].[ppeople_disciplines] [extent18]                         [extent17].[id] = [extent18].[people_id]                     )  [project10]                     (ltrim(rtrim([project10].[discipline])) in (n'rr', n'iar', n'ins', n'tax', n'trst', n'mrtg', n'bd', n'ria')) , (ltrim(rtrim([project10].[discipline])) not null) , ((@p__linq__0 = 1) or (@p__linq__1 = 1) or ( exists (select                          1 [c1]                         [dbo].[ppeople_discipline_agents] [extent19]                         ([project10].[id] = [extent19].[people_discipline_id]) , ([extent19].[agent_id] in (cast(5307 bigint), cast(241 bigint), cast(242 bigint), cast(271 bigint), cast(274 bigint), cast(275 bigint), cast(276 bigint), cast(373 bigint), cast(543 bigint), cast(754 bigint), cast(760 bigint), cast(761 bigint), cast(793 bigint), cast(794 bigint), cast(795 bigint), cast(796 bigint), cast(832 bigint), cast(833 bigint), cast(834 bigint), cast(938 bigint), cast(1370 bigint), cast(1580 bigint), cast(1733 bigint), cast(1809 bigint), cast(1857 bigint), cast(1903 bigint), cast(1951 bigint), cast(2265 bigint), cast(2391 bigint), cast(2397 bigint), cast(2423 bigint), cast(2556 bigint), cast(2567 bigint), cast(2581 bigint), cast(2743 bigint), cast(2744 bigint), cast(2745 bigint), cast(2819 bigint), cast(3153 bigint), cast(3162 bigint), cast(3166 bigint), cast(3212 bigint), cast(3227 bigint), cast(3398 bigint), cast(3634 bigint), cast(3722 bigint), cast(3757 bigint), cast(3820 bigint), cast(3862 bigint), cast(3871 bigint), cast(4393 bigint), cast(4461 bigint), cast(4565 bigint), cast(4592 bigint), cast(4742 bigint), cast(4955 bigint), cast(5002 bigint), cast(5104 bigint), cast(5234 bigint), cast(5254 bigint), cast(5306 bigint), cast(5321 bigint), cast(5322 bigint)))                     )))                 )) , ([extent17].[holdingcompanyid] = @p__linq__2) , ([extent17].[confirmationneededtypeid] null)             )  [project13]             ( exists (select                  1 [c1]                  [dbo].[ppeople_groups] [extent21]                 inner join [dbo].[groups] [extent22] on [extent21].[group_id] = [extent22].[id]                 ([project13].[id] = [extent21].[people_id]) , ((len([extent22].[group_type])) = 0)             )) , (1 =  cast( [project13].[personstatustypeid] int)) , ([project13].[isdeleted] <> cast(1 bit)) , ([project13].[c1] > 0) ) [project15]         cross apply  (select              case when ([extent27].[id] null) cast(null int) else 1 end [c1],              [extent24].[person1id] [person1id],              --many 'extents' edited out here                 [dbo].[personrelationship] [extent23]             left outer join [dbo].[personrelationshipmarriagedetail] [extent24] on ([extent23].[relationshiptypeid] = [extent24].[relationshiptypeid]) , ([extent23].[person2id] = [extent24].[person2id]) , ([extent23].[person1id] = [extent24].[person1id])             inner join [dbo].[person] [extent25] on [extent23].[person1id] = [extent25].[id]             inner join [dbo].[person] [extent26] on [extent23].[person2id] = [extent26].[id]             left outer join [dbo].[ppeople_disciplines] [extent27] on [extent27].[people_id] = [extent23].[person1id]             [project15].[id] = [extent23].[person2id]         union             select              2 [c1],              [extent29].[person1id] [person1id],              --many 'extents' edited out here             [extent32].[level] [level]                 [dbo].[personrelationship] [extent28]             left outer join [dbo].[personrelationshipmarriagedetail] [extent29] on ([extent28].[relationshiptypeid] = [extent29].[relationshiptypeid]) , ([extent28].[person2id] = [extent29].[person2id]) , ([extent28].[person1id] = [extent29].[person1id])             inner join [dbo].[person] [extent30] on [extent28].[person1id] = [extent30].[id]             inner join [dbo].[person] [extent31] on [extent28].[person2id] = [extent31].[id]             inner join [dbo].[ppeople_disciplines] [extent32] on ([extent28].[person2id] = [extent31].[id]) , ([extent32].[people_id] = [extent31].[id])             [project15].[id] = [extent28].[person2id]) [unionall2]) [unionall3] union     select      3 [c1],      3 [c2],      [project23].[id] [id],      [join19].[global] [global]       (select          [extent33].[id] [id],          [extent33].[profilepicturepath] [profilepicturepath],          (select              count(1) [a1]             [dbo].[ppeople_disciplines] [extent36]             [extent33].[id] = [extent36].[people_id]) [c1]         [dbo].[person] [extent33]         ( exists (select              1 [c1]             ( select                  [extent34].[id] [id],                  [extent34].[discipline] [discipline]                 [dbo].[ppeople_disciplines] [extent34]                 [extent33].[id] = [extent34].[people_id]             )  [project20]             (ltrim(rtrim([project20].[discipline])) in (n'rr', n'iar', n'ins', n'tax', n'trst', n'mrtg', n'bd', n'ria')) , (ltrim(rtrim([project20].[discipline])) not null) , ((@p__linq__0 = 1) or (@p__linq__1 = 1) or ( exists (select                  1 [c1]                 [dbo].[ppeople_discipline_agents] [extent35]                 ([project20].[id] = [extent35].[people_discipline_id]) , ([extent35].[agent_id] in (cast(5307 bigint), cast(241 bigint), cast(242 bigint), cast(271 bigint), cast(274 bigint), cast(275 bigint), cast(276 bigint), cast(373 bigint), cast(543 bigint), cast(754 bigint), cast(760 bigint), cast(761 bigint), cast(793 bigint), cast(794 bigint), cast(795 bigint), cast(796 bigint), cast(832 bigint), cast(833 bigint), cast(834 bigint), cast(938 bigint), cast(1370 bigint), cast(1580 bigint), cast(1733 bigint), cast(1809 bigint), cast(1857 bigint), cast(1903 bigint), cast(1951 bigint), cast(2265 bigint), cast(2391 bigint), cast(2397 bigint), cast(2423 bigint), cast(2556 bigint), cast(2567 bigint), cast(2581 bigint), cast(2743 bigint), cast(2744 bigint), cast(2745 bigint), cast(2819 bigint), cast(3153 bigint), cast(3162 bigint), cast(3166 bigint), cast(3212 bigint), cast(3227 bigint), cast(3398 bigint), cast(3634 bigint), cast(3722 bigint), cast(3757 bigint), cast(3820 bigint), cast(3862 bigint), cast(3871 bigint), cast(4393 bigint), cast(4461 bigint), cast(4565 bigint), cast(4592 bigint), cast(4742 bigint), cast(4955 bigint), cast(5002 bigint), cast(5104 bigint), cast(5234 bigint), cast(5254 bigint), cast(5306 bigint), cast(5321 bigint), cast(5322 bigint)))             )))         )) , ([extent33].[holdingcompanyid] = @p__linq__2) , ([extent33].[confirmationneededtypeid] null) ) [project23]     inner join  (select [extent37].[id] [id1], [extent37].[people_id] [people_id], [extent37].[group_id] [group_id], [extent37].[remarks] [remarks], [extent37].[start_date] [start_date], [extent37].[end_date] [end_date], [extent37].[status] [status], [extent38].[id] [id2], [extent38].[agency_id] [agency_id], [extent38].[agent_id] [agent_id], [extent38].[name] [name], [extent38].[description] [description], [extent38].[deleted] [deleted], [extent38].[user_created] [user_created], [extent38].[group_type] [group_type], [extent38].[global] [global]          [dbo].[ppeople_groups] [extent37]         inner join [dbo].[groups] [extent38] on [extent37].[group_id] = [extent38].[id] ) [join19] on [project23].[id] = [join19].[people_id]     ( exists (select          1 [c1]          [dbo].[ppeople_groups] [extent39]         inner join [dbo].[groups] [extent40] on [extent39].[group_id] = [extent40].[id]         ([project23].[id] = [extent39].[people_id]) , ((len([extent40].[group_type])) = 0)     )) , (1 =  cast( [project23].[personstatustypeid] int)) , ([project23].[isdeleted] <> cast(1 bit)) , ([project23].[c1] > 0)) [unionall4] order [unionall4].[c3] asc, [unionall4].[c1] asc, [unionall4].[c28] asc, [unionall4].[c29] asc, [unionall4].[c30] asc, [unionall4].[c34] asc, [unionall4].[c37] asc, [unionall4].[c38] asc, [unionall4].[c45] asc, [unionall4].[c46] asc, [unionall4].[c47] asc, [unionall4].[c49] asc, [unionall4].[c75] asc, [unionall4].[c100] asc, [unionall4].[c115] asc, [unionall4].[c116] asc, [unionall4].[c117] asc, [unionall4].[c121] asc, [unionall4].[c124] asc, [unionall4].[c125] asc, [unionall4].[c132] asc, [unionall4].[c133] asc, [unionall4].[c134] asc, [unionall4].[c136] asc, [unionall4].[c162] asc, [unionall4].[c187] asc 

to list of persongroup objects, use where instead of any:

expression = (x => x.persongroups.where(y => y.group.grouptype == null || y.group.grouptype == ""));  return expression 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -