c# - "An EdmType cannot be mapped to CLR classes multiple times" when called via LINQ Expressions. Guessing EDMX is loaded twice -
i have mvc3 app edmx model:
<add name="mfimodelcontainer" connectionstring="metadata=res://mfi/models.mfimodel.csdl|res://mfi/models.mfimodel.ssdl|res://mfi/models.mfimodel.msl;provider=system.data.sqlclient;provider connection string="data source=villain\sqlexpress;initial catalog=sistem;user id=sa; password=pasword;multipleactiveresultsets=true;app=entityframework"" providername="system.data.entityclient" /> sometimes have need dynamic stuff (parse strings, create linq expressions, compile , call).
i have simple function:
public static decimal payment(order sd, string arg) { mfimodelcontainer mf = new mfimodelcontainer(); kredit k = mf.dokumenti.oftype<kredit>().single(a => a.ugovor == sd.intproperty2); datamodelcontainer db = new datamodelcontainer(); list<kreditotplata> ko = mf.kreditotplate.where(a => a.kredit == k.iddokument).tolist(); // calculations... if (arg == "r") return sd.amount.value * 80m / 100m; else return sd.amount.value * 20m / 100m; } i call function part of linq expression (something following):
type common = assembly.loadfile("path assembply").gettype("mfi.models.common"); methodinfo mi = common.getmethod("payment", bindingflags.static | bindingflags.public); expression call = expression.call(mi, expression.parameter(typeof(order)), expression.constant(typeof(string))); return expression.lambda(selectexpr, expression.parameter(typeof(order))).compile().dynamicinvoke(instance_of_order); after call, if instantiate mfimodelcontainer "normally" (in regular code) "multiple mapping error".
also, if first instantiate mfimodelcontainer "normally", , via linq expressions again error.
if use 1 method exclusivelly, ok.
so, presume, edmx loaded twice, dont know it.
i must stress edmx not defined in primary dll of mvc app, in additional one, hooked in global.asax (i feel might important).
could me pointers should resolve this?
best regards,
ok, answer question.
it turns out
assembly.loadfile() is not @ resolving dependencies.
so, switched
assembly.loadfrom() and all right.
regards.
Comments
Post a Comment