Friday, March 25, 2011

calling a Stored Procedure using Entity Framework

Any stored procedure can be called through EF. Create a SP and add it to your model. Further go to the model browser, right click the sp, and click add function import, here select your SP, and select what type it returns, if it returns nothing then select 'None'. If it returns a sclar type then select the type, and if its returning a recordset then select complex. Click on get column information, it will show you the colums returning. click on create new complex type. and click ok. If its returning one of you entities then click on option entity and select the entity type from the list box.

now you call call it in your code.

if its returning a complex type use code:

MyEntities _entities = new MyEntities();
var p = from d in _entities.GetOrderInfo() select d;

if its returning nothing then use code:

MyEntities _entities = new MyEntities();
_entities.Cancel_Sale(ucode, oid);

No comments:

Post a Comment