TPH - Same column name
Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4621
Printed Date: 06-Sep-2025 at 4:26am
Topic: TPH - Same column name
Posted By: smi-mark
Subject: TPH - Same column name
Date 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
|
Replies:
Posted By: kimj
Date 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).
|
Posted By: smi-mark
Date 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.
|
|