使用自定义SQL查询与LINQ to SQL ...帮助

时间:2009-11-27 00:18:28

标签: linq-to-sql

我已经将Scott的这个教程与T对照我自己的数据库。

http://weblogs.asp.net/scottgu/archive/2007/08/27/linq-to-sql-part-8-executing-custom-sql-expressions.aspx

我在Partial类中遇到错误。

当前上下文中不存在名称“ExecuteQuery”。我不能为我的生活弄清楚出了什么问题。

public partial class MerchantsAppDataContext
{

    public IEnumerable<SubmittalDetails> GetSubmittalDetails(string minDate)
    {
        var sqlTxt = "SELECT Submittals.SubmittalID, Submittals.Created AS     DateFiled, " +
            "CheckDetails.Status AS CheckStatus, CheckDetails.CheckNumber,     CheckDetails.DateWritten, CheckDetails.FaceAmount, CheckDetails.Reference,     CheckDetails.ExhibitNo AS ExhibitNumber, " +
            "CheckWriterDetails.FirstName, CheckWriterDetails.LastName " +
            "FROM Submittals " +
            "INNER JOIN LocationAccepted ON Submittals.LocationAcceptedID =     LocationAccepted.LocationAcceptedID " +
            "INNER JOIN CheckDetails ON LocationAccepted.LocationAcceptedID = CheckDetails.LocationAcceptedID AND Submittals.SubmittalID = CheckDetails.SubmittalID " +
            "INNER JOIN CheckWriterDetails ON CheckDetails.CheckWriterID = CheckWriterDetails.CheckWriterID " +
            "WHERE (CheckDetails.DateWritten >= {0})" +
            "ORDER BY   Submittals.Created DESC, Submittals.SubmittalID,     CheckDetails.CheckDetailsID ";


        return ExecuteQuery<SubmittalDetails>(sqlTxt, minDate);
    }


}



public class SubmittalDetails
{

    public int SubmittalID { get; set; }
    public string Created { get; set; }
    public int LocationAccepted { get; set; }

}

1 个答案:

答案 0 :(得分:0)

编译器无法找到分部类的另一半,因此无法看到它是一个DataContext。

检查自动生成的文件MerchantsAppDataContext.designer.cs里面定义了部分类MerchantsAppDataContext的命名空间,并确保在代码中使用相同的命名空间。

namespace ??? // TODO: Use the same namespace as MerchantsAppDataContext.designer.cs
{
    public partial class MerchantsAppDataContext
    {
        public IEnumerable<SubmittalDetails> GetSubmittalDetails(string minDate)
        {
            ...
        }
    }
}