entity framework 4 - Selecting Related Entities When No Association Exists -


ef4 great pulling in associated data do when association not explicit? example illustrates situation:

mastertable has child1id , child2id column.

there 2 tables child1 , child2 corresponding primary key child1id , child2id. there master, child1 , child2 entities.

there no foreign key or entity framework association between master , child1 / child2 tables or entities.

how can select master records , corresponding child records 2 child tables when have matching child ids in master?

i can't retrofit relationship or association.

richard

you must select them manually linq entities. here how left join between 2 tables:

var query = m in context.masters             m.id == 1             join c in context.childs on m.child.id equals c.id leftjoin             x in leftjoin.defaultifempty()             select new                 {                     id = x.id,                     name = x.name,                     child = x.childs                 }; 

btw. if entities have property contains value of pk other entity can create relation in ef designer. in such case able use navigation properties.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -