c# - Is it possible for one entity to take data from two tables? -


is possible have 1 entity takes data 2 tables?

for example.

table1 has columns: id, name, table2_id

table2 has columns: id, fullname

i have entity properties: id, name, fullname

what expect configure (fluently) entity framework build query:

select t1.id, t1.name, t2.fullname table1 t1 join table2 t2 on t1.table2_id = t2.id 

is possible without has 2 separated entities , 1 merge both?

after quick google find how merge data tables 1 entity. need configure entity framework this

modelbuilder.entity<myentity>() .map( m => {  m.properties(x=> new { x.id, x.name });  m.totable("table1"); }) .map( m => {  m.property(x=>x.fullname);  m.totable("table2"); }); 

but how tell entity framework join tables on table2_id table1 , id table2.

i know can create view , map entity view, if possible i'd use scenario presented.

yes, if id same in both tables, can make 1:1 mapping map single entity.

you can table per concrete type inheritance, in inherited properties go in 1 table, , derived properties go in another.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -