2009-11-27 83 views
0

我跟隨本教程由斯科特對我自己的數據庫很大的T。使用自定義SQL查詢與LINQ to SQL ...幫助

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

我在我的部分類得到一個錯誤。

名稱'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; } 

} 

回答

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) 
     { 
      ... 
     } 
    } 
} 
+0

感謝馬克,它解決了它... – JBeckton 2009-11-27 01:01:16