c# - Explicitly load related entities in many-to-many relationship with Entity Framework over WCF -
i'm using ef 4.1 self-tracking entities in layered application uses wcf hand entities , forth client server.
a portion of database contains 3 tables:
customer contact customercontacts
customercontacts
contains 2 primary keys of customer
, contact
, edm represents navigation properties - customer.contacts
, contacts.customers
. customercontacts
table not represented otherwise in model, meaning there no customercontacts
entity, understand , expect feature of edm designer when representing many-to-many relationships of form.
the situation have list of customer
s bound combobox
, wish load related contact
s of customer
@ point when selected in combobox
. put way, wish explicilty load customer.contacts
when customer
selected in combobox
. can't use customer.id
in where
fetch list of contacts
, since there no join entity in model relates them.
currently, loading copy of customer
, using include("contacts")
contact
s , setting via selectedcustomer.contacts = temporarycustomer.contacts;
does know of method doesn't require fetch redundant, temporary copy of customer
?
you know id
of selected customer can pass wcf parameter , query contacts related customer:
var customercontacts = context.contacts .where(c => c.customers.any(cu => cu.id == passedid));
anyway should think replacing wcf stes wcf data services more suitable scenarios , support many features (including loading of navigation property) out-of-the-box.
Comments
Post a Comment