c# - How to use EntityFramework CodeFirstStoreFunctions nuget package? -
i trying access existing function in db. want execute function code first.
searching net found:
https://codefirstfunctions.codeplex.com/
my implementation of this:
protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<trainmessage>() .property(e => e.latitude) .hasprecision(18, 16); modelbuilder.entity<trainmessage>() .property(e => e.longitude) .hasprecision(18, 16); modelbuilder.entity<stop>() .property(e => e.stop_lat) .hasprecision(18, 16); modelbuilder.entity<stop>() .property(e => e.stop_lon) .hasprecision(18, 16); modelbuilder.entity<order>() .property(e => e.latitude) .hasprecision(18, 16); modelbuilder.entity<order>() .property(e => e.longitude) .hasprecision(18, 16); modelbuilder.entity<subscription>() .property(e => e.starttime) .hasprecision(0); modelbuilder.entity<subscription>() .property(e => e.endtime) .hasprecision(0); modelbuilder.entity<orderlocation>() .property(e => e.latitude) .hasprecision(18, 16); modelbuilder.entity<orderlocation>() .property(e => e.longitude) .hasprecision(18, 16); modelbuilder.entity<order>() .hasmany(e => e.orderlocations) .withoptional(e => e.order) .hasforeignkey(e => e.order_id); modelbuilder.conventions.add(new functionsconvention<transitcontext>("dbo")); } [dbfunction("transitcontext", "tvf_getallstopsinbetween")] public iqueryable<int> getallstopsbetweenstations(int stopa_id, int stopb_id) { var = new objectparameter("stopa_id", stopa_id); var b = new objectparameter("stopb_id", stopb_id); return ((iobjectcontextadapter)this).objectcontext .createquery<int>("[dbo.tvf_getallstopsinbetween](@stopa_id, stopb_id)", a, b); }
it not show in guide have function in db , create in code figure not need rest of code.
i have 2 problems this
1) no matter data trying db get:
the argument 'name' cannot null, empty or contain white space.
2) when remove part of code:
modelbuilder.conventions.add(new functionsconvention<transitcontext>("dbo"));
i this:
errordescription = "'dbo.tvf_getallstopsinbetween' cannot resolved valid type or function."
message = "'dbo.tvf_getallstopsinbetween' cannot resolved valid type or function. near escaped identifier, line 1, column 1."
i new codefirst , inherited code.
how solve this?
i got
the argument 'name' cannot null, empty or contain white space.
when using nuget package.
i cloned codeplex repo , used source directly , error went away. think nuget out of date
Comments
Post a Comment