entity framework - Map two different entities to the same table? -


i have table in database lot of fields. most of time need fields. there 1 scenario, however, need few of fields, , loading ton of rows.

what i'd add in entity manually, , map original table, delete columns don't need. set up, rather self-explanatory error of:

problem in mapping fragments ...entitysets 'fmvhistorytrimmed' , 'fmvhistories' both mapped table 'fmvhistory'. primary keys may collide.

is there other way should go this? again, of time of columns used, don't want trim down original entity , put "extra" fields complex type.

you can't map 2 regular entities same table. have several choices:

  1. use table splitting.
  2. use custom query projection non entity type (as @aducci proposed)
  3. use queryview
  4. use database view or directly definingquery

table splitting

table splitting allows map table 2 entities in 1:1 relation. first entity contain pk , subset of fields need always. second entity contain other fields , pk. both entities contain navigation property each other. if need subset of fields query first entity. if need fields query first entity , include navifation property second entity. can lazy load second entity if need it.

queryview

queryview esql query defined directly in mapping (msl) , mapped new readonly entity type. can use queryview define projection of full entity subentity. queryview must defined manually in edmx (it not available in designer). know queryview not available in code first same custom projection non entity type.

definingquery

definingquery custom query defined directly in storage model (ssdl). definingquery used when mapping database views can use custom sql select. map result of query readonly entity type. definingquery must defined manually in edmx (it not available in designer). not directly avaliable in code first same calling sqlquery on dbdatabase. problem definingquery once manually define in ssdl can't use update model database because operation replaces complete ssdl , deletes query definition.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -