I'm in the process of rewriting of our webapis to .NET Core and using EntityFrameworkCore 5.0. In our previous iteration we used EntityFramework 6. We are moving this app so we can host it on azure.
I'm new to EFCore and was noticing some differences that I can't seem to get around.
We have an entity that will use mapping from two tables, one is a view and the other is the actual table that the object will live in. The last part contains the stored procedures to insert, update, and delete entries in the dbo.PhoneFaxEmail table.
The Previous EF6 code is below.
Map(m =>
{
m.ToTable("HomeownerContactDetails_vw", "monarch");
m.Properties(h => new { h.HomeownerId, h.Id, h.StartDate, h.EndDate });
m.Requires("RelationTypeLUKey").HasValue(587); // Contact-PhoneFaxEmail (p-c)
m.Property(h => h.HomeownerId).HasColumnName("ParentRelationKey");
m.Property(h => h.Id).HasColumnName("ChildRelationKey");
});
#endregion
#region PhoneFaxEmail Mapping
Map(m =>
{
m.ToTable("dbo.PhoneFaxEMail");
m.Properties(h => new { h.Type, h.Value, h.ValidDate, h.Status, h.Version });
m.Property(h => h.Id)
.HasColumnName("RelationKey");
m.Property(h => h.Type).HasColumnName("PhoneFaxEMailTypeLUKey");
m.Property(h => h.Value).HasColumnName("Value");
m.Property(h => h.ValidDate).HasColumnName("StatusDate");
m.Property(h => h.Status).HasColumnName("StatusLUKey");
m.Property(a => a.CreatedBy).HasColumnName("CreatedBy");
m.Property(a => a.CreatedDate).HasColumnName("CreatedDate");
m.Property(a => a.ModifiedBy).HasColumnName("ModifiedBy");
m.Property(a => a.ModifiedDate).HasColumnName("ModifiedDate");
});
#endregion
MapToStoredProcedures(s =>
{
s.Insert(i => i.HasName("HomeownerContactDetailCreate_sp", "monarch"));
s.Update(u =>
{
u.HasName("HomeownerContactDetailUpdate_sp", "monarch");
u.Parameter(p => p.Id, "RelationKey");
u.Parameter(p => p.Version, "Version");
});
s.Delete(i =>
{
i.HasName("HomeownerContactDetailDelete_sp", "monarch");
i.Parameter(p => p.Id, "RelationKey");
i.Parameter(p => p.Version, "Version");
});
});
The issue I am having in .NET Core is that there is no Map() function and no MapToStoredProcedures() function. I'm not sure where to go from here to get the Entity mapped to the two separate tables, and how EF Core maps procs (or of it even does map procs in the same manner).
I tried to do Entity Splitting with this code, but the 'm' lamba expression results to a TableBuilder object, which only has 2 methods, m.ExcludeFromMitigations() and m.GetType().
pfeEntity.ToTable("dbo.PhoneFaxEmail");
pfeEntity.Property(b => b.Id).HasColumnName("RelationKey");
pfeEntity.Property(b => b.Value).HasColumnName("Value");
pfeEntity.ToTable("HomeownerContactDetails_vw", "monarch", m =>
{
m.Property(b => b.BlogId).HasColumnName("Id");
m.Property(b => b.Url);
});
Any help would be greatly appreciated! (even if I'm totally approaching this the wrong way, like I said, totally new and want to learn all I can about EFCore!)