c# - Upgrading Entity Framework 1.0 to 4.0 to include foreign keys -
currently i've been working entity framework 1.0 located under service façade.
below 1 of save methods i've created either update or insert device in question.
this works but, can't feel bit of hack having set referenced properties null re-attach them insert work. changeddevice holds these values, why need assign them again.
so, thought i'll update model ef4. way can directly access foreign keys. however, on doing i've found there doesn't seem easy way add foreign keys except removing entity diagram , re-adding it. don't want i've been through entity properties renaming them db column names. can help?
/// <summary> /// saves non network device. /// </summary> /// <param name="nonnetworkdevicedto">the non network device dto.</param> public void savenonnetworkdevice(nonnetworkdevicedto nonnetworkdevicedto) { using (var context = new assetnetworkentities2()) { var changeddevice = transformationhelper.convertnonnetworkdevicedtotoentity(nonnetworkdevicedto); if (!nonnetworkdevicedto.deviceid.equals(-1)) { var originaldevice = context.nonnetworkdevices.include("status").include("nonnetworktype").firstordefault( d => d.deviceid.equals(nonnetworkdevicedto.deviceid)); context.applyallreferencedpropertychanges(originaldevice, changeddevice); context.applycurrentvalues(originaldevice.entitykey.entitysetname, changeddevice); } else { var maxnetworkdevice = context.nonnetworkdevices.orderby("it.deviceid desc").first(); changeddevice.deviceid = maxnetworkdevice.deviceid + 1; var status = changeddevice.status; var nonnetworktype = changeddevice.nonnetworktype; changeddevice.status = null; changeddevice.nonnetworktype = null; context.attachto("devicestatuses", status); if (nonnetworktype != null) { context.attachto("nonnetworktypes", nonnetworktype); } changeddevice.status = status; changeddevice.nonnetworktype = nonnetworktype; context.addtononnetworkdevices(changeddevice); } context.savechanges(); } }
you going need edit edmx file in xml editor then. maybe update 1 table automatically, diff edmx file see changed , go in , edit others.
renaming field names bold risky move if using database-first approach. renaming fields in database better names preferable if have flexibility.
the other issue encounter ef4 going want pluralize entity names unless ask not to. if update model ef1 ef4 , let pluralize names remember go check weakly typed include() calls, , while fixing them change them 1 of many typed .include()'s you'll find on web.
Comments
Post a Comment