Featured post
c# 4.0 - Can't query EF context under TPL -
i've got process read thousands of records database, encode each individual xml message , send said message off wcf service.
the database referenced via ef4 model. i'm using tpl parallelize creation of xml messages. problem occurs first linq query:
var practice = (from patient in db.t_accountholder join practitioner in db.t_practitioner on patient.defaultpractitioner_id equals practitioner.practitioner_id join _practice in db.t_practice on practitioner.practice_id equals _practice.practice_id patient.accountholder_id == accountholder_id select _practice).firstordefault();
i following exception:
argumentexception: item same key has been added.
after lots of research found out ef doesn't assign new key queried results, meaning if query same table same result, above exception occur (because result in same datacontext).
since i'm using tpl, i'm in exact situation. recourse not use ef? go normal ado.net queries?
i've searched , down excellent site , google, can't seem find similar type of question.
edit: here stack trace of error.
exception message: item same key has been added. @ system.throwhelper.throwargumentexception(exceptionresource resource) @ system.collections.generic.dictionary`2.insert(tkey key, tvalue value, boolean add) @ system.data.objects.objectstatemanager.addstatemanagertypemetadata(entityset entityset, objecttypemapping mapping) @ system.data.objects.objectstatemanager.getoraddstatemanagertypemetadata(type entitytype, entityset entityset) @ system.data.objects.objectstatemanager.addentry(ientitywrapper wrappedobject, entitykey passedkey, entityset entityset, string argumentname, boolean isadded) @ system.data.common.internal.materialization.shaper.handleentityappendonly[tentity](func`2 constructentitydelegate, entitykey entitykey, entityset entityset) @ lambda_method(closure , shaper ) @ system.data.common.internal.materialization.coordinator`1.readnextelement(shaper shaper) @ system.data.common.internal.materialization.shaper`1.simpleenumerator.movenext() @ system.linq.enumerable.firstordefault[tsource](ienumerable`1 source) @ system.data.objects.elinq.objectqueryprovider.<getelementfunction>b__1[tresult](ienumerable`1 sequence) @ system.data.objects.elinq.objectqueryprovider.executesingle[tresult](ienumerable`1 query, expression queryroot) @ system.data.objects.elinq.objectqueryprovider.system.linq.iqueryprovider.execute[s](expression expression) @ system.linq.queryable.firstordefault[tsource](iqueryable`1 source) @ wcfservicetest.messages.createaccountholdermessage(int32 accountholder_id) in c:\users\chris\documents\visual studio 2010\projects\wcfservicetest\wcfservicetest\messages.cs:line 116 @ wcfservicetest.messages.createparallelmessagesforaccountholder(int32 accountholder_id, manmayentities _db, list`1 queue) in c:\users\chris\documents\visual studio 2010\projects\wcfservicetest\wcfservicetest\messages.cs:line 2482 @ wcfservicetest.parallelwork.<>c__displayclass22.<processdata_ef>b__1f(int32 patient_id) in c:\users\chris\documents\visual studio 2010\projects\wcfservicetest\wcfservicetest\parallelwork.cs:line 298
after lots of research found out ef doesn't assign new key queried results, meaning if query same table same result, above exception occur (because result in same datacontext).
that's not right. it's fine run same query more once. try in test application.
if select same object context twice, default instances fixed same object. see docs objectquery.mergeoption
.
you usually see error give when addobject()
twice same object.
i think bug may elsewhere.
btw, write query this:
var practice = (from patient in db.t_accountholder patient.accountholder_id == accountholder_id select patient.practitioner.practice).firstordefault();
shouldn't make difference issue, though.
- Get link
- X
- Other Apps
Comments
Post a Comment