Reputation: 1085
I read about querying database using the entity framework
var result = _dbContext.SqlQuery<string>(sql, someParamSqlParameter).ToList();
What if i wanted multiple columns to be returned how could i write that type of query. I tried this code but it gives some sql schema mapping error
var result = clsGlobalObjectRefrances.SchoolSoulController.Stt.Database.SqlQuery<LocalAccGroups>(sqlQuery).ToList();
var sqlQuery = "Select GroupId,GroupName,Level from cte_AccGroups";
Where LocalAccGroups is a class i created
class LocalAccGroups
{
public decimal GroupId { get; set; }
public string GroupName { get; set; }
int Level { get; set; }
}
Thanxxx in Advance
Upvotes: 0
Views: 2842
Reputation: 223422
Your query is returning Level
as well, and you haven't marked your property Level
in your class as public. Mark your property as public and it should be good. Also make sure that the data type matches the one returned by query. It seems odd go a GroupId
to be of type decimal.
class LocalAccGroups
{
public decimal GroupId { get; set; }
public string GroupName { get; set; }
public int Level { get; set; }
}
Upvotes: 1