How can i execute raw query in my API using entity frame work data model. I was able to retrieve data through Linq but now i want some specific data because of which i am executing a raw query.
When i run the below code i get an exception
"The operation cannot be completed because the DbContext has been disposed."
I do understand the exception n when i google it, its telling me to check the connection, may be there is some bracket misplaced, but i don't know where.
Also if this is the correct way to execute a raw query in c# MVC using entity framework, m i missing something?
What I have tried:
public HttpResponseMessage Get(int EmployeeId)
{
var masterInfo = entities.Empmasters.where(e => e.EmployeeId ==
EmployeeId).FirstOrDefault();
var emppersonal = entities.EmpMaster.Where(p => p.EmployeeID ==
masterInfo.EmployeeID).FirstOrDefault();
int value = empersonal.Gender;
var Gender = entities.LookUps.SqlQuery(" SELECT LookUpName FROM LookUp WHERE
LookUpType = 'GENDER' AND LookUpValue = @value ", new sqlParameter("
@value" , value));
if (masterInfo == null)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "No info");
}
else
{
return Request.CreateResponse(HttpStatusCode.OK, new {masterInfo,
empPersonal
Gender = gender});
}