Entity Framework: 0..1-to-many foreign key constraint not recognized? -


i using ef4 map db schema object model; generated edmx database have been editing xml directly (trying leave ssdl same while changing csdl/msl approximate object model want). database contains, among many other things, couple tables (0..)1-to-many constraint via foreign key so:

go create table options (     kitnodeid int primary key foreign key references kitnodes (kitnodeid),     [skuid] int null foreign key (skuid) references skus (skuid) ) go create table upgrades (     upgradeid int identity (1, 1) primary key not null,     [name] nvarchar(50) not null,     defaultoptionid int null references options (kitnodeid) ) 

the relevant sections in edmx this:

[...]

<!-- ssdl content -->         <edmx:storagemodels>         <schema namespace="dmodel.store" alias="self" provider="system.data.sqlclient" providermanifesttoken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/entitystoreschemagenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">             <entitycontainer name="dmodelstorecontainer">        <associationset name="fk__upgrades__defaul__70ddc3d8" association="dmodel.store.fk__upgrades__defaul__70ddc3d8">         <end role="options" entityset="options" />         <end role="upgrades" entityset="upgrades" />       </associationset> </entitycontainer>     <entitytype name="upgrades">       <key>         <propertyref name="upgradeid" />       </key>       <property name="upgradeid" type="int" nullable="false" storegeneratedpattern="identity" />       <property name="name" type="nvarchar" nullable="false" maxlength="50" />       <property name="defaultoptionid" type="int" />     </entitytype> <association name="fk__upgrades__defaul__70ddc3d8">           <end role="options" type="dmodel.store.options" multiplicity="0..1" />           <end role="upgrades" type="dmodel.store.upgrades" multiplicity="*" />           <referentialconstraint>             <principal role="options">               <propertyref name="kitnodeid" />             </principal>             <dependent role="upgrades">               <propertyref name="defaultoptionid" />             </dependent>           </referentialconstraint>         </association> </schema></edmx:storagemodels>  <!-- csdl content -->     <edmx:conceptualmodels>       <schema namespace="dmodel" alias="self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">         <entitycontainer name="dentities" annotation:lazyloadingenabled="true"> <entityset name="upgrades" entitytype="dmodel.upgrade" />           <associationset name="upgrade_defaultoption" association="dmodel.upgrade_defaultoption">             <end role="options" entityset="options" />             <end role="upgrades" entityset="upgrades" />           </associationset> </entitycontainer>   <association name="upgrade_defaultoption">           <end role="options" type="dmodel.option" multiplicity="0..1" />           <end role="upgrades" type="dmodel.upgrade" multiplicity="*" />         </association> <entitytype name="upgrade">           <key>             <propertyref name="upgradeid" />           </key>           <property name="upgradeid" nullable="false" annotation:storegeneratedpattern="identity" type="int32" />           <property name="name" type="string" nullable="false" maxlength="50" unicode="true" fixedlength="false" />           <navigationproperty name="defaultoption" relationship="dmodel.upgrade_defaultoption" fromrole="upgrades" torole="options" />           <navigationproperty name="optinoptions" relationship="dmodel.optinoptions" fromrole="upgrades" torole="options" />         </entitytype>      </schema>     </edmx:conceptualmodels>     <!-- c-s mapping content -->     <edmx:mappings>       <mapping space="c-s" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">         <entitycontainermapping storageentitycontainer="dmodelstorecontainer" cdmentitycontainer="dentities">           <entitysetmapping name="upgrades"><entitytypemapping typename="dmodel.upgrade"><mappingfragment storeentityset="upgrades">             <scalarproperty name="upgradeid" columnname="upgradeid" />             <scalarproperty name="name" columnname="name" />           </mappingfragment></entitytypemapping></entitysetmapping>  <associationsetmapping name="upgrade_defaultoption" typename="dmodel.upgrade_defaultoption" storeentityset="fk__upgrades__defaul__70ddc3d8">             <endproperty name="upgrades">               <scalarproperty name="upgradeid" columnname="upgradeid"/>             </endproperty>             <endproperty name="options">               <scalarproperty name="kitnodeid" columnname="defaultoptionid"/>             </endproperty>           </associationsetmapping>  </entitycontainermapping>       </mapping>     </edmx:mappings> 

it generate code, when try use "error 2007: table 'fk_upgrades_defaul__70ddc3d8' specified part of msl not exist in metadataworkspace." looks can't find underlying foreign key constraint ssdl supposed use, see 1 name in database.

really, feel don't have understanding of how kind of mapping supposed work in general - foreign key constraint in database treated "associationset"? - closest can work out. don't know if diagnose problem info i've given, pointers on look? i've tried various things changing storeentityset point options, etc. result in different errors.

try changing how define foreign key, see: how create foreign key in sql server?

you have delete , recreate model.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -