c# - How to serve utility data in Odata? -
c# - How to serve utility data in Odata? -
i want have utilitycontroller utility methods serve info in odata api in microsoft asp.net. if want implement controller based on entity product
have productcontroller
edmmodelbuit
builder.entityset<product>("product");
with other types if in product
type e.g.
builder.entityset<productgroup>("productgroup");
now solution if want have controller utilitycontroller
methods getanylist
, getoffertypes
, putnewenumtypeinofferbase
, not have utility type etc, utility info related entity or may not. e.g
public class utilitycontroller : odatacontroller { private dbcontext db = new dbcontext(); public list<string> getofferbase() { homecoming utilityservice.getofferbase(); } protected override void dispose(bool disposing) { db.dispose(); base.dispose(disposing); } }
then can utility info
http://localhost:47120/odata/utility/getofferbase
unbound function/action match requirement. applying them, can send such requests not need entity set:
1. http://host/odata/getofferbase 2. post http://host/odata/putnewenumtypeinofferbase
to add together unbound function/action need this:
odataconventionmodelbuilder builder = new odataconventionmodelbuilder(); builder.function actionconfiguration putnewenumtypeinofferbase = modelbuilder.action("putnewenumtypeinofferbase"); putnewenumtypeinofferbase .parameter<string>("title"); putnewenumtypeinofferbase .returnsfromentityset<movie>("movies"); builder.function("getsalestaxrate") .returns<double>() .parameter<string>("state");
for more, please refer: https://aspnet.codeplex.com/sourcecontrol/latest#samples/webapi/odata/v4/odatafunctionsample/ https://aspnet.codeplex.com/sourcecontrol/latest#samples/webapi/odata/v4/odataactionssample/
c# web-services asp.net-mvc-4 asp.net-web-api odata
Comments
Post a Comment