Entity Framework CTP4 non-standard primary key name usage in BaseEntity -
I have already been struggling for several days to solve my problem with primary key usage. Please, someone helps me solve this puzzle !!!
I am using the Entitie Framework with CTP4, the first approach of code I adopted for my project repository pattern published by Huuru, I get very out of this parental and especially CTP 4 possibilities. I am
For unit definitions, we use many nesting layers. At very little we have a basement, which includes some common fields, such as:
public abstract class basentity: iTTABase {public virtual faucet & lt; System. Datetime & gt; {Receive inputs; Set; } Public virtual faucet qualified & lt; Int & gt; PK_InsertUserAccount {get; Set; } Public Virtual Byte [] Timestamp {Received; Set; }}
Then we obtain from this class for our concrete entities, for example:
Public class person: BaseInty {Public Virtual Ink PK_Person {get; Set; } Public Virtual Byte PersType {get; Set; } Public virtual string e-mail {get; Set; } Public Virtual String {get} Set; }}
Note! We have an important difference - DB table primary key name is not "ID"! Because we are using pattern PK_, we do not include the PK field definition in the BaseInternet. In addition, we use EntityConfiguration
to mapping our non-conventional primary key:
public class personmapping: entity configuration & lt; Person & gt; {Public Person Mapping () {this.HasKey (P => P. PK_ Person); this. Property (P => P. PK_ Person). IIIDent (); This.MapSingleType () ToTable ("dbo.Person") .; // otherwise it has been converted to "people" by the conference}}
And here are the problems when I try to use the person unit, I get an error 'Unit Type' KDC Unable to guess a key for the model. Antiques Basantity '' It seems that ObjectContext needs to define the primary key in very very base classes. Because, when I take the PK field definition on baseline for experimental purposes, everything works fine. But in our case this is not possible, because for each table we differnet primary key field name
I do not know the way and where I am wrong! Please help me! Instead of using MapSingleType, try using MapHierarchy and specifying fields.
For example
modelbuilder.Entity & lt; Person & gt; (). Mapharkaiki (P => New {p.PK_Person, p.PersPype, p.Name, p.eMail, P.Instandard Date, P.PK_INSARTUserAccount, P. Timestamp}). Broken ("person");
Comments
Post a Comment