Using Entity Framework 5.0 map relationship between parent and children when ID are Guids with newsequentialid() -
i have 2 classes 1 many relationship.
public partial class client { public client() { this.client_local = new hashset<client_local>(); } public system.guid guid { get; set; } public string name { get; set; } public virtual icollection<client_local> client_local { get; set; } } public partial class client_local { public system.guid localguid { get; set; } public system.guid guid { get; set; } public string cultureid { get; set; } public string localname { get; set; } public virtual client client { get; set; } } the mapping classes are:
class clientmapping : entitytypeconfiguration<client> { public clientmapping() { this.haskey(entity => entity.guid); //as newsequentialid() this.totable("client"); this.property(entity => entity.guid).hasdatabasegeneratedoption(databasegeneratedoption.identity); } } class client_localmapping : entitytypeconfiguration<client_local> { public client_localmapping() { this.haskey(entity => entity.localguid); // as newsequentialid() this.totable("client_local"); this.property(entity => entity.localguid).hasdatabasegeneratedoption(databasegeneratedoption.identity); this.hasrequired<client>(e => e.client).withmany(p => p.client_locals).hasforeignkey<guid>(c => c.guid); } } i can create new instances of client class , save them database successfully. when try , add client_local class , save database "a dependent property in referentialconstraint mapped store-generated column. column: 'guid'.".
the key fields generated in sql newsequentialid performance reasons. , there foreign key relationship between client_local.guid , client.guid.
retrieving data database works above mapping classes. appreciated.
Comments
Post a Comment