trying to make a generic SQL Query via a method that will fetch data i was making this code
public ObjectResult<theSelectedTableNameModel> getUsersRes(string sqlStr, string ColNameAsfilter, string FiltersValue,string OrderByFilter="")
{
string SqlCmd = "";
string By = "";
if (OrderByFilter.isNotEmptyOrNull())
By = string.Concat(" ORDER BY ", OrderByFilter);
SqlCmd = string.Format("{0} WHERE {1}={2}{3}", SqlStr, ColNameAsfilter, FiltersValue, By);
return anEntityName.ExecuteStoreQuery<theSelectedTableNameModel>(SqlCmd);
}
i have copied my code and edited real names and other variables /parameters so i might have made a mistake, but the question is , how could i make it more generic than this ?
this is a working approach that lets me specify the query of the sqlCommand
i wanted it to fit any entity and any model/object/table
how could it be done ? i guess there's a ready solution for this or the engeniring of EF not ment to be generic... i'm using asp.net 4.0 , and latest EF..
I think you need something like this
Follow this link