New Posts New Posts RSS Feed: TPH - Same column name
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

TPH - Same column name

 Post Reply Post Reply
Author
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Topic: TPH - Same column name
    Posted: 05-Dec-2013 at 1:12pm
I'm attempting to use Table Per Hierarchy for the first time, and the following scenario is supposed to work in EF6 but doesn't seem appear to work with DevForce when generating the ibmmx.


Example:

BaseEntity
  Id
  Name

Entity1
  ForeignKeyId

Entity2
  ForeignKeyId

Entity3
 SomeOtherProperty

The default behavior is it will create ForeignKeyId and ForeignKeyId1

so the solution is to add the [Column] attribute to each to define it as ForeignKeyId to use the fluent api like:

modelBuilder.Entity<Entity1>().Property(p => p.ForeignKeyId).HasColumnName("ForeignKeyId");
modelBuilder.Entity<Entity2>().Property(p => p.ForeignKeyId).HasColumnName("ForeignKeyId");


When you do so, you get the following error:

Error    7    An error occurred during metadata generation and a metadata file could not be created.  Error: One or more validation errors were detected during model generation:

ForeignKeyId: : There is no property with name 'ForeignKeyId' defined in the type referred to by Role 'BaseEntity'.

I really would like them to both map to ForeignKeyId otherwise it is going to clutter up the table, and I might as well switch to a TPT scenario in that case.

I hope I've explained that correctly. Let me know if you need any more information.

Thanks,

Mark
 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 05-Dec-2013 at 4:57pm
This error is actually coming from EF when we try to access the metadata to construct the ibmmx.  It looks like this might be work item 583 on the EF codeplex site, but the site appears to be down at the moment so I can't verify this.   The work item is marked as closed and fixed, but there might be more information there on the site (once it's back up).
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 05-Dec-2013 at 5:00pm
I read that issue, which is why I assumed it was working in EF. Apparently not then, if that's where the error is coming from.




Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down