我的部分课程出现错误.名称"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; }}解决方案编译器无法找到部分类的另一半,因此看不到它是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) { ... } }}I have followed this tutorial by Scott pretty much to the T against my own database.http://weblogs.asp.net/scottgu/archive/2007/08/27/linq-to-sql-part-8-executing-custom-sql-expressions.aspxI am getting an error in my Partial class.The name 'ExecuteQuery' does not exist in the current context. I cannot for the life of me figure out what went wrong.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; }} 解决方案 The compiler is unable to find the other half of the partial class, and so it can't see that it is a DataContext.Check the auto-generated file MerchantsAppDataContext.designer.cs to which namespace the partial class MerchantsAppDataContext is defined inside, and make sure you use the same namespace in your code.namespace ??? // TODO: Use the same namespace as MerchantsAppDataContext.designer.cs{ public partial class MerchantsAppDataContext { public IEnumerable<SubmittalDetails> GetSubmittalDetails(string minDate) { ... } }} 这篇关于结合使用自定义SQL查询和LINQ to SQL ...帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-05 04:12