Read data using DbDataReader Storeprocedure in Entityframework
How to use store procedure outputparameter with Entity Framework?
Read data using DbDataReader Storeprocedure in Entityframework, we also see how to deal with Output parameter.
required namespace
using System.Collections.Generic;
using System.Data;
using System.Data.Objects;
using System.Data.SqlClient;
using System.Linq;
now look at the implementation, its very simple and saves lots of time.
public List SearchProduct1(string SearchText, string SearchBy, string Area, string countryId, int startRowIndex, int maximumRows, ref int TotalRows)
{
List< myProductInfo > objLst = new List< myProductInfo >();
int? _startRowIndex = startRowIndex;
int? _maximumRows = maximumRows;
int? _TotalRows = TotalRows;
int? _contryId = countryId == “” ? 0 : Convert.ToInt32(countryId);
try
{
using (var myEntities = new ApplicationEntities())
{
// this is how you can set the output parameter.
ObjectParameter param = new ObjectParameter(“TotalRows”, typeof(int));
/* here you probably wondering where the “SearchProduct” function come from, well open your edmx file and right click => import function, now select the sp you want to execute, then write the function name as your business need (ex. SearchProduct)
*/
objLst = myEntities.SearchProduct(SearchText, SearchBy, Area, _contryId, _startRowIndex, _maximumRows, param).ToList< myProductInfo >();
TotalRows = Convert.ToInt32(pTotalRows.Value);
}
}
catch (Exception ex)
{
this.Status = ex.ToString();
}
return objLst;
}