简体   繁体   English

Linq to Sql与存储过程

[英]Linq to Sql with Stored Procedure

I am trying to use stored procedure in dbml, but I get below error. 我试图在dbml中使用存储过程,但出现以下错误。 The Stored procedure has 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' 非静态字段,方法或属性“ 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 来自http://msdn.microsoft.com/en-us/library/79b3xss3.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM