Entity splitting with EF Code First issue

c# ef-code-first entity-framework entity-framework-6

Popular Answer

Even though I was very certain that I had this mapping functioning before, I nevertheless took a somewhat alternative path.

I mapped it as an object with a 1:1 relationship after first removing the surrogate key on "OrganizationSettings" (which was maybe not technically necessary).

Now in My Organization Settings are:

public class OrganizationSettings
{
    public int OrganizationId { get; set; }
    public bool AllowMultipleTimers { get; set; }
}

OrganizationId functions as a foreign key as well as a primary key.

The configuration is as follows:

        var org = modelBuilder.Entity<Organization>()
            .Map(u =>
            {
                u.Properties(m => new { m.TenantId, m.Name });
            })
            .HasRequired(m => m.Settings)
            .WithRequiredPrincipal();


        modelBuilder.Entity<OrganizationSettings>()
            .HasKey(m => m.OrganizationId);

And it appears that this is effective. Because I'm not disclosing aDbSet for OrganizationSettings it keeps the conceptual modeling ofOrganizationSettings as an intact valuable object.

1
5/28/2015 9:44:54 PM


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