c# - How to do a proper left join in Entity Framework -


this should simple problem solve, reason entity framework makes hard me. need simple left join...

i have 2 tables. example, user table:

user_id | name | fk_group_id 

and group table

group_id | groupname 

in raw sql:

select * users u left join groups g on u.fk_group_id = g.group_id groupname = 'my group' 

super easy in sql. when search answers on how entity framework, there's 1 thing immidiately goes through mind... wtf...!?!? super large constructed, weird formatted "queries" performed , i'm confused need , not...

so i'm hoping me specific problem. how 1 rewrite above sql query in (linq?) entity framework.

currently have this:

var bla = (from m in myent.users           // join attempt..           join mp in myent.groups on m equals mp.group_id n           n.group_name == "something"           select m); 

even if working, don't see how suppose make life easier.. oo

anyway, hope can me out :-)

umm, don't have explicitly orm. that's catch here, that's mapping's for.

you can go:

var blah = myent.users.where(user => user.group.name == "something"); 

or in alternate syntax

from usr in myent.users usr.group.name == "something" select usr` 

if it's many-to-one relationship after mapping objects, every user entity have navigation property group, , every group have user collection. have filter results appropriately.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -