How to set up Entity Framework to map two classes to the same table -


i've been bumbling along ef5 cant seem 2 domain classes map single database table.

the error is:

   message: "the type 'basd.erp.wms.purchasing.supplierprofile' has been configured entity type. cannot reconfigured complex type." 

this dbcontext:

    public class purchasingcontext : disconnectedentitycontext     {         public dbset<suppliercard> suppliers { get; set; }         public dbset<purchasecategory> purchasecategories { get; set; }          public purchasingcontext() : this("basd.erp.wms") { }          public purchasingcontext(string connectionstringname) : base(connectionstringname) { }          public static purchasingcontext getinstance(efdataprovider provider) { return new purchasingcontext(provider.connectionstringname); }     } } 

these classes:

namespace basd.erp.wms.purchasing {      public class suppliercard : contactcard, isuppliercard     {         private icollection<purchasecategory> _purchasecategories;          public icollection<purchasecategory> purchasecategories         {             { return _purchasecategories; }             set { setnotifyfield(ref _purchasecategories, value, () => purchasecategories); }         }          public supplierprofile profile { get; protected set; }          private suppliercard()         {             this.profile = new supplierprofile();             this.purchasecategories = new collection<purchasecategory>();         }          public suppliercard(long id, string alf, string name)             : this(id, alf, new simplenameholder(name), new collection<iphysicaladdress>(), new digitaladdresses()) { }          public suppliercard(long id, string alf, inameholder nameholder,                             icollection<iphysicaladdress> physicaladdresses, idigitaladdresses digitaladdresses)             : this(id, alf, nameholder, physicaladdresses, digitaladdresses, null) { }          public suppliercard(long id, string alf, inameholder nameholder,            icollection<iphysicaladdress> physicaladdresses, idigitaladdresses digitaladdresses, ivalidatableobject validator)             : base(id, alf, nameholder, physicaladdresses, digitaladdresses, validator)         {             this.profile = new supplierprofile();             this.purchasecategories = new collection<purchasecategory>();         }     } }    public class supplierprofile : abstractaspect     {           private tradingentity _inctype;          public tradingentity businesstype         {             { return _inctype; }             set             {                 if (_inctype != null) { this.deregistersubpropertyforchangetracking(this.businesstype); }                 _inctype = value; this.onpropertychanged("tradingtype");                 this.registersubpropertyforchangetracking(this.businesstype);             }         }          private bool _emailok;         private bool _smailok;          public bool marketingemailok         {             { return _emailok; }             set { _emailok = value; this.onpropertychanged("marketingemailok"); }         }           public bool marketingsmailok         {             { return _smailok; }             set { _smailok = value; this.onpropertychanged("marketingsmailok"); }         }          public supplierprofile()             : base()         {             this.businesstype = new tradingentity(contactlegaltype.limited);         }     } } 

these configuration classes:

 [export(typeof(ientityconfiguration))]     public class suppliercardconfiguration         : entitytypeconfiguration<suppliercard>, ientityconfiguration     {          public suppliercardconfiguration()         {             this.totable("suppliercard", "erp_wms");             haskey(u => u.id);             property(u => u.id).hascolumnname("supplierid");             ignore(u => u.usepropertynotifications);             property(u => u.profile.marketingemailok).hascolumnname("marketingemailok");             hasmany(i => i.purchasecategories)                 .withmany(c => c.suppliers)                 .map(mc =>                 {                     mc.mapleftkey("categoryid");                     mc.maprightkey("supplierid");                     mc.totable("supplierpurchasecategory", "erp_wms");                 });         }           public void addconfiguration(configurationregistrar registrar)         {             registrar.add(this);         }     }   [export(typeof(ientityconfiguration))]     public class supplierprofileconfiguration         : entitytypeconfiguration<supplierprofile>, ientityconfiguration     {          public supplierprofileconfiguration()         {             this.totable("suppliercard", "erp_wms");             ignore(u => u.usepropertynotifications);             property(u => u.marketingemailok).hascolumnname("marketingemailok");         }           public void addconfiguration(configurationregistrar registrar)         {             registrar.add(this);         }     } 

update:

ok ive tried ignoring supplierprofile per suggestion changed nothing. tried removing configuration class supplier profile , left

 protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         modelbuilder.ignore<supplierprofile>();         base.onmodelcreating(modelbuilder);     } 

and generated error:

{"the property 'profile' not declared property on type 'suppliercard'. verify property has not been explicitly excluded model using ignore method or notmappedattribute data annotation. make sure valid primitive property."} [system.invalidoperationexception]: {"the property 'profile' not declared property on type 'suppliercard'. verify property has not been explicitly excluded model using ignore method or notmappedattribute data annotation. make sure valid primitive property."}

i tried removing

 protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         modelbuilder.ignore<supplierprofile>();         base.onmodelcreating(modelbuilder);     } 

while leaving out configuration class supplierprofile , generates error:

message: "invalid column name 'profile_businesstype_contactlegaltype'.\r\ninvalid column name 'profile_businesstype_tradingsince'.\r\ninvalid column name 'profile_businesstype_state'.\r\ninvalid column name 'profile_businesstype_usepropertynotifications'.\r\ninvalid column name 'marketingemailok'.\r\ninvalid column name 'profile_marketingsmailok'.\r\ninvalid column name 'profile_state'.\r\ninvalid column name 'profile_usepropertynotifications'.\r\ninvalid column name 'ownerid'.\r\ninvalid column name 'state'."

so said, **bumbling** along ;)

after reading this think might have relationship in suppliercard class.

public class suppliercard : contactcard, isuppliercard {   public supplierprofile profile { get; protected set; } } 

i'm guessing registering complex type when suppliercard mapped. suggested way fix ignore it.

modelbuilder.ignore<supplierprofile>(); 

i've never run problem myself, not sure if this'll help.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -