Sunday, 15 May 2011

c# - InvalidCastException When Calling Attach Entity Framework 5 -



c# - InvalidCastException When Calling Attach Entity Framework 5 -

i 1 time 1 time again have unusual problem entity framework.

i want to:

send hashset of objects method load these objects database update 1 of fields in each of objects save objects database, either @ 1 time or individually

some of code is:

for each bi generalbasketitem in useddiscitems using db new till1entities1 db.generalbasketitem.attach(bi)

''i tried having context outside , within each experiment this.

part of db schema: http://imgur.com/ka47zju

the lastly line sometimes, not throwing next exception:

system.invalidcastexception unhandled user code hresult=-2147467262 message=unable cast object of type 'system.data.entity.dynamicproxies.promappliedpromdisc_052d0bc99a5a9e842b5774e34c71c0ade6170e70600ade549aaa5f0eea48e49f' type 'coretilldal.prombaskitemdisc'. source=system.data.entity

stacktrace: @ system.data.objects.dataclasses.entityreference1.addtolocalcache(ientitywrapper wrappedentity, boolean applyconstraints) @ system.data.objects.entityentry.takesnapshotofsinglerelationship(relatedend relatedend, navigationproperty n, object o) @ system.data.objects.entityentry.takesnapshotofrelationships() @ system.data.objects.internal.entitywrapperwithoutrelationships1.takesnapshotofrelationships(entityentry entry) @ system.data.objects.objectcontext.attachsingleobject(ientitywrapper wrappedentity, entityset entityset, string argumentname) @ system.data.objects.dataclasses.relatedend.addentitytoobjectstatemanager(ientitywrapper wrappedentity, boolean doattach) @ system.data.objects.dataclasses.relatedend.addgraphtoobjectstatemanager(ientitywrapper wrappedentity, boolean relationshipalreadyexists, boolean addrelationshipasunchanged, boolean doattach) @ system.data.objects.dataclasses.relatedend.includeentity(ientitywrapper wrappedentity, boolean addrelationshipasunchanged, boolean doattach) @ system.data.objects.dataclasses.entityreference1.include(boolean addrelationshipasunchanged, boolean doattach) @ system.data.objects.dataclasses.relationshipmanager.addrelatedentitiestoobjectstatemanager(boolean doattach) @ system.data.objects.objectcontext.attachto(string entitysetname, object entity) @ system.data.entity.internal.linq.internalset1.<>c__displayclass2.b__1() @ system.data.entity.internal.linq.internalset1.actonset(action action, entitystate newstate, object entity, string methodname) @ system.data.entity.internal.linq.internalset1.attach(object entity) @ system.data.entity.dbset1.attach(tentity entity) @ coretilldal.promsetprice.adjustbaskitems(hashset1 useddiscitems) in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\dbpromplugin1\plugins classes\promanddisc\promsetpricee.vb:line 60 @ coretilldal.generalbasket.adjustbisforproms() in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\dbpromplugin1\core classes\ef ext classes\till\generalbaskete.vb:line 245 @ coretilldal.generalbasket.applybiandbaskdiscounts() in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\dbpromplugin1\core classes\ef ext classes\till\generalbaskete.vb:line 174 @ coretilldal.potappliedprom.savepromotiontobasketoritems(int64 promidforthisval, boolean manualactivation, int64 basketid, dictionary`2 usedbuyitems, boolean test) in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\dbpromplugin1\plugins classes\promclasses\potentialproms\potappliedprom.vb:line 172 @ promplugin.dpromautoapplicator.applybestpromotiontoitems() in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\promdomainplugin\autopromotions\dpromautoapplicator.vb:line 92 @ promplugin.dpromautoapplicator.calcandapplypromstobasket(generalbasketitem newbasketitem) in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\promdomainplugin\autopromotions\dpromautoapplicator.vb:line 59 @ promplugin.dpromcontroller.handlebaskitemadded(object o, baskitemaddedeventargs e) in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\promdomainplugin\autopromotions\dpromcontroller.vb:line 53 @ coretilldal.coretill.addbasketitem(int64 basketid, int64 productid) in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\dbpromplugin1\core classes\ef ext classes\till\coretill.vb:line 29 @ unittests.testingstoredprocs.addbasketitemstotriggerprom(generalbasket basket, int64 promid, dpromcontroller& promcont) in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\unittests\testingstoredprocs.vb:line 545 @ unittests.testbasictests.testallbasicpromsauto() in c:\users\neil.clarke\documents\visual studio 2012\projects\plugins\unittests\testclasses\testbasictests.vb:line 265 innerexception:

i have no thought why. may able see 2 types referenced:

promappliedpromdisc prombaskitemdisc

are not type trying attach (generalbasketitem) unsure why mentioned. promappliedpromdisc navigation property (fk) of generalbasketitem. prombaskitemdisc navigation property (fk) of promappliedpromdisc.

i have seen problem when ef trying cast 1 of navigation properties generalbasketitem type.

can help? haven't found similar problems online.

i found cleaning solution , rebuilding has been getting rid of error now.

i guess 1 of vs bugs.

c# .net vb.net entity-framework entity-framework-5

No comments:

Post a Comment