Reputation: 1473
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.
Upvotes: 4
Views: 2601
Reputation: 1039
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.
Upvotes: 0
Reputation: 14535
Not implemented yet, as can be seen in this open ticket: https://github.com/aspnet/EntityFramework/issues/619
Upvotes: 2