Table Per Type (TPT): Specify Key
-
Monday, February 07, 2011 6:57 PM
I have 2 tables in an existing Database:
CountryG:
ID,
NameCountry:
CountryID,
ClientIDThe ForeignKey goes from Country.CountryID to CountryG.ID.
My classes should look like this:
[Table("bdCountryG")] public class CountryG { [Key] public string ID { get; set; } public string Name { get; set; } } [Table("bdCountry")] public class Country : CountryG { public int ClientID { get; set; } }
Since the name of the PrimaryKey/ForeignKey-column is not the same, I get an error when using it in code first.
I do not know how to specify the different foreign-key with the fluent api. I found samples to rename foreign keys, but not in an TPT example.thx for any help on this.
All Replies
-
Tuesday, February 08, 2011 12:29 AM
interesting question. I tried this
modelBuilder.Entity<CountryG>().ToTable("CountryG");
modelBuilder.Entity<Country>()
.Map(mc =>
{
mc.Properties(c => new { CountryID = c.ID, c.Name, c.ClientID });
}).ToTable("Country");;The above code gave me an exception
Entity splitting cannot be specified for type 'Country' since it is part of an inheritance hierarchy.I am not really doing entitysplitting. its just table per type inheritance with control over column names.
Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
http://weblogs.asp.net/zeeshanhirani -
Tuesday, February 08, 2011 4:43 AM
this is what I tried too, of course same results.
Does anybody know a solution how to specify the name of the key-columns in a TPT scenario? -
Tuesday, February 08, 2011 4:26 PM
Can please somebody help us out here.
We are trying very hard to use TPT with special keynames, but it does not seem to be supported.A clear statement wether this is supported or not would be very helpful.
thx, emikelsoft
-
Wednesday, February 09, 2011 8:50 PMModerator
Hi,
Unfortunately this isn't possible at this stage. I realize this isn't a great answer but one option would be to create a view that renames the PK/FK column and then map to that.
~Rowan
- Proposed As Answer by Rowan MillerMicrosoft Employee, Moderator Wednesday, February 09, 2011 8:50 PM
- Marked As Answer by emikelsoft Wednesday, February 09, 2011 10:57 PM
-
Wednesday, February 09, 2011 10:57 PM
Dear Rowan!
Many thx, this work around does it for me.
one question: Is the release for code first still on schedule (end of March 2011)?
We are just in the progress of porting a big project to this technology and we are very excited of the features of CTP5.thx & br, emikelsoft
-
Thursday, February 10, 2011 6:39 AMwell rowan said "this isn't possible at this stage" prob means that they are locked down so i am thinking we are getting very close...
Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
http://weblogs.asp.net/zeeshanhirani -
Thursday, February 17, 2011 6:44 PMModerator
Hi,
We are still on track to offer a go-live release this quarter. We're closing on dates at the moment and will share all the info in a blog post in a couple of weeks.
~Rowan
-
Saturday, February 11, 2012 2:44 AM
Hi,
Unfortunately this isn't possible at this stage. I realize this isn't a great answer but one option would be to create a view that renames the PK/FK column and then map to that.
~Rowan
Has this been addressed in any of the more recent EF releases?
Thanks!
Terry.
They're all dead Dave.

