EF4 CTP5, mapping different entities to the same (existing) table?

Mapping 2 entity to one table requires that you create a Complex Type or Table Per erarchy (TPH) You can't just map 2 entities to one table like this. Let me know which one is better describe your domain model and I will provide you with the required object model/fluent API code.

Mapping 2 entity to one table requires that you create a Complex Type or Table Per You can't just map 2 entities to one table like this. Let me know which one is better describe your domain model and I will provide you with the required object model/fluent API code. Update: TPH Mapping: public abstract class EntityBase { Column(Name = "MyTable_ID") public string ID { get; set; } Column(Name = "MyTable_Discriminator") public string Discriminator { get; set; } } public class EntityA : EntityBase { Column(Name = "MyTable_TimeStamp") public string TimeStamp { get; set; } } public class EntityB : EntityBase { Column(Name = "MyTable_CreatedBy") public string CreatedBy { get; set; } } public class StackoverflowTestContext : DbContext { public DbSet Entities { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .

HasKey(x => new { x. ID, x. Discriminator }); modelBuilder.Entity() .

Map(m => m. Requires("TPHDiscriminator") . HasValue("yourDesiredValueForA")) .

Map(m => m. Requires("TPHDiscriminator") . HasValue("yourDesiredValueForB")) .

ToTable("MyTable"); } }.

Seems like TPH might be the better option here. With TPH and discriminator, I guess we can make our little example work? – Mathieu Hétu Jan 15 at 17:40 That's what I thought too.So given that TPH will create a Discriminator column for you, do you still need to have a Discriminator property in your EntityA and EntityB?

– Morteza Manavi Jan 15 at 17:49 Nope, we are working on an existing DB schema, that we cannot alter in any way... – Mathieu Hétu Jan 15 at 17:50 I've updated the answer with a TPH mapping, see how this one works out for you. – Morteza Manavi Jan 15 at 18:06 Thanks... I am trying it in my domain 'à l'instant' :-) – Mathieu Hétu Jan 15 at 18:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions