c# - Assign the result of stored procedure into a variable using Entity Framework -
i'm new entity framework orm while using dataset orm can assign stored procedure result variable
mydatasettbladapter mydata = new mydatasettbladapter(); string result = mydata.mystoredprocedure().tostring(); and works fine .. in entity framework i'm trying same
onlinedvdshopdbentities dbcontext = new onlinedvdshopdbentities(); string result = dbcontext.spaddgetusername().tostring(); remember stored procedure returning single value
this pretty straight forward.
// initialize dependency data entities private entities _datacontext; public classname() { _datacontext = new entities(); } public iqueryable<entityname> methodname(string filter) { // initialize var records = _datacontext.entity // constrain results .where( x => filter == null || x.property1.contains(filter) ); return records; } if expecting single value might use
var records = _datacontext.entity.firstrdefault(); firstordefault() returns first element of sequence match criteria. use singleordefault(), given need 1 result.
https://msdn.microsoft.com/en-us/library/vstudio/bb340482%28v=vs.100%29.aspx https://msdn.microsoft.com/en-us/library/vstudio/bb342451%28v=vs.100%29.aspx
Comments
Post a Comment