我得到非静态方法需要一个目标错误,当我用谷歌搜索它时,我看到了检查空值的帖子,在我的数据中,我所有的值都声明为非空,不知道为什么我会收到这个错误。请帮忙。
我的代码:
我通过调用 Db 获得了总结果
var result = _retailerStatsRepository.GetAllRetailersForManufacturerCountryAndCategorySelectedDates(manufacturerRow.Id,
countryRow.Id,
categoryRow.Id,
cumLeads.StartDate,
cumLeads.EndDate);
笔记:
我正在尝试使用 Linq 将结果用于我的进一步查询
retailerWeeklyClickCount = result.Where(
i =>
i.Date >= localStart && i.Date <= localEnd && i.RetailerId == retailer.Id &&
i.ManufacturerId == manufacturerRow.Id
&& i.CountryId == countryRow.Id && i.CategoryId == categoryRow.Id).Sum(i => i.WidgetClicks);
我收到错误,所以我在下面尝试
编辑
var retailerWeeklyClicks = result.Where(
i =>
i.Date >= localStart && i.Date <= localEnd && i.RetailerId == retailer.Id &&
i.ManufacturerId == manufacturerRow.Id
&& i.CountryId == countryRow.Id && i.CategoryId == categoryRow.Id);
if(retailerWeeklyClicks!=null)
{
retailerWeeklyClickCount = retailerWeeklyClicks.Sum(i => i.WidgetClicks);
}
但是仍然遇到相同的错误并检查了我的数据库,并且在我选择的类别的开始日期和结束日期之间的几天内我没有数据。
堆栈跟踪 :
在 System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target) 在 System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] 参数, CultureInfo 文化) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr、Binder binder、Object[] 参数、CultureInfo 文化)
在 System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfoculture) 在 System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index) 在 System.Data.Objects。 ELinq.QueryParameterExpression.TryGetFieldOrPropertyValue(MemberExpression me, Object instance, Object& memberValue) at System.Data.Objects.ELinq.QueryParameterExpression.TryEvaluatePath(Expression expression, ConstantExpression& constantExpression) at System.Data.Objects.ELinq.QueryParameterExpression.EvaluateParameter(Object[]参数)在 System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery
1.GetResults(Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator() 在 System.Linq.Enumerable.Single[TSource](IEnumerable1 source) at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable
1 序列)在 System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable1 query, Expression queryRoot) at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Linq.Queryable.Sum[TSource](IQueryable
1 源,表达式1 selector) at reporting.e_tale.co.uk.Controllers.ReportsController.CumLeadsParameters(CumLeadsReport cumLeads) in d:\e-tale-core-development\trunk\reporting.e-tale.co.uk\Controllers\ReportsController.cs:line 492 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2 个参数)在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 延续)
由于我是 Linq 的新手,如果我做错了什么,请帮助我。