gpt4 book ai didi

c# - Linq to SQL : NullReferenceException in System. Data.Linq.SqlClient.QueryConverter.VisitInvocation(InvocationExpression 调用)

转载 作者:行者123 更新时间:2023-11-30 18:08:45 26 4
gpt4 key购买 nike

下面的 L2S 代码位给我这个非常奇怪的堆栈跟踪。如果我附加一个调试器并在此调试器上设置一个断点,看起来问题出在评估 transactions.Count() 上。谁能具体看看是什么原因造成的?请注意,Transactions 表中没有行落入此 where 子句。

L2S 片段:

var transactions = (from t in DataContext.Transactions
where t.TransactionDate.Date == date.Date && company.Id == t.Customer.CompanyId
select t);

if (transactions.Count() > 0) // Exception thrown here (transactions.Count())
{
foreach (var transaction in transactions)
{
transaction.Detach();
}
}

返回交易;

堆栈跟踪:

[NullReferenceException: Object reference not set to an instance of an object.]
System.Data.Linq.SqlClient.QueryConverter.VisitInvocation(InvocationExpression invoke) +471
System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1370
System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +30
System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression b) +27
System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +449
System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +30
System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression b) +40
System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +449
System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +30
System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression sequence, LambdaExpression predicate) +136
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +4173
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +70
System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1025
System.Data.Linq.SqlClient.QueryConverter.VisitAggregate(Expression sequence, LambdaExpression lambda, SqlNodeType aggType, Type returnType) +84
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +6371
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +70
System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1025
System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node) +111
System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations) +114
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +132
System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute(Expression expression) +23
System.Linq.Queryable.Count(IQueryable`1 source) +243
MyProject.Repositories.TransactionRepository.GetTransactionsOn(DateTime date, Company company) in D:\Build\MyProject\Source\MyProject\Repositories\TransactionRepository.cs:38
MyProject.Web.Widgets.RunningSalesTotalWidget.GetView() in D:\Build\MyProject\Source\MyProject\Web\Widgets\RunningSalesTotalWidget.cs:26
MyProject.Web.WidgetController.Render(ViewContext viewContext) in D:\Build\MyProject\Source\MyProject\Web\WidgetController.cs:38
MyProject.Web.Helpers.WidgetExtensions.RenderWidget(HtmlHelper helper, Int32 id) in D:\Build\MyProject\Source\MyProject.Web\Helpers\WidgetExtensions.cs:20
ASP.views_home_index_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer) in d:\Build\MyProject\Source\MyProject.Web\Views\Home\Index.aspx:9
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\Build\MyProject\Source\MyProject.Web\Views\Shared\Site.Master:30
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +56
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060

完全迷失在这一点上。如果有人可以在这里提供任何帮助,我们将不胜感激!

最佳答案

您的一个子表可能是罪魁祸首。我刚遇到这个错误,这是由于将空对象传递给辅助函数。不幸的是,您无法深入了解。

关于c# - Linq to SQL : NullReferenceException in System. Data.Linq.SqlClient.QueryConverter.VisitInvocation(InvocationExpression 调用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3012147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com