Entity Framework Core table Splitting approach

c# entity-framework entity-framework-core

Question

In Entity Framework 6, you can split the entity to be saved in multiple tables with the feature MAP:

modelBuilder.Entity<Employee>()  
  .Map(map =>  
  {  
  map.Properties(p => new  
  {  
     p.EmployeeId,  
     p.Name,  
     p.Code  
  });  
  map.ToTable("Employee");  
  })  
  // Map to the Users table  
  .Map(map =>  
  {  
  map.Properties(p => new  
  {  
     p.PhoneNumber,  
     p.EmailAddress  
  });  
  map.ToTable("EmployeeDetails");  
  });  

I was wondering if somebody knows if this is possible to do on entity framework core, I've searching about it a long time and didnt find anything similar.

At the moment, I'm using Dtos with composition to solve this problem, but is getting annoying to work with as the solution is growing.

Any help would be appreciated, Thanks.

1
3
12/23/2016 12:22:04 PM

Accepted Answer

Not implemented yet, as can be seen in this open ticket: https://github.com/aspnet/EntityFramework/issues/619

2
12/23/2016 2:42:13 PM

Popular Answer

If you need to split your entity between different tables, one approach is the one you mentioned, not currently implemented on EF_core.

The other option is to create a View on the DB side and configure the entity to receive the data from there. ( The drawback of this approach, obviously, is that you'll have to include custom logic to be able to add, update or remove elements from this model.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow