c# - EF SqlQuery multi-mapping -


does ef sqlquery has multi-mapping feature in dapper?

see: fill list object using dapper c#

ef join queries results not expected.

example:

models:

public class tlb {     [key]     public int tlbid { get; set; }     public bool ispublished { get; set; }     public virtual icollection<tlbattachment> attachments { get; set; }     public virtual icollection<tlbattachment> othercollection1 { get; set; }     public virtual icollection<tlbattachment> othercollection2 { get; set; } }  public class tlbattachment {     [key, column(order = 0)]     public int attachmentid { get; set; }      [foreignkey("attachmentid")]     public virtual attachment attachment { get; set; }      [key, column(order = 1)]     public int tlbid { get; set; }      [foreignkey("tlbid")]     public virtual tlb tlb { get; set; } }  public class attachment {     [key]     public int attachmentid { get; set; }     public int type { get; set; } } 

db access:

const string query = "select * " +                      "from tlb t left outer join "+                      "tlbattachment @ on at.tlbid = t.tlbid left outer join "+                      "attachment on a.attachmentid = at.attachmentid " +                      "where t.ispublished = 1 , a.type = 0";  return _dbcontext.database.sqlquery<model.tlb>(query); 

the result of sqlquery doesn't contain attachments , don't want othercollection1 , othercollection2. seems in dapper can change mapping. using include in web api, both othercollection1 , othercollection2 called in lazy-loading mode. , don't need them.

if need feature load associations, ef has build-in support using include method. otherwise there no such functionality multi-mapping.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -