Linq to Sql with Stored Procedure
I am trying to use stored procedure in dbml, but I get below error. The Stored procedure h开发者_如何学Goas multiple join tables, but it returns a row.
public static List<SP_EMP_MASTER_DETAILResult> GetEmployeeDetail(string userName, string userLocation)
{
var query = (from q in db.SP_EMP_MASTER_DETAIL(userLocation, userName)
select new SP_EMP_MASTER_DETAILResult { ID = q.EMP_ID, Name = q.EMP_NM }).ToList();
return query;
}
This is an error.
An object reference is required for the non-static field, method, or property 'Tiger.Models.HomeRepository.db'
Your method is static... IS your db variable static also? You can't reference a non-static class member in your static method.....
Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.
from http://msdn.microsoft.com/en-us/library/79b3xss3.aspx
精彩评论