相关疑难解决方法(0)

非静态方法需要目标

我有一个控制器动作,可以在本地和生产中使用Firefox,在本地使用IE,但在生产中不是IE.这是我的控制器动作:

public ActionResult MNPurchase()
{
    CalculationViewModel calculationViewModel = (CalculationViewModel)TempData["calculationViewModel"];

    decimal OP = landTitleUnitOfWork.Sales.Find()
        .Where(x => x.Min >= calculationViewModel.SalesPrice)
        .FirstOrDefault()
        .OP;

    decimal MP = landTitleUnitOfWork.Sales.Find()
        .Where(x => x.Min >= calculationViewModel.MortgageAmount)
        .FirstOrDefault()
        .MP;

    calculationViewModel.LoanAmount = (OP + 100) - MP;
    calculationViewModel.LendersTitleInsurance = (calculationViewModel.LoanAmount + 850);

    return View(calculationViewModel);
}
Run Code Online (Sandbox Code Playgroud)

这是我在IE中获得的堆栈跟踪:

错误.处理您的请求时发生错误.System.Reflection.TargetException:非静态方法需要一个目标.System.Reflection.RuntimeMethodInfo.Invoke的System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化)中的System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)处于System.Reflection.RuntimeMethodInfo.Invoke(Object obj, System.Data.Objects.ELinq.QueryParameterExpression.TryGetFieldOrPropertyValue(MemberExpression me,Object instance,System.Reflection.RuntimePropertyInfo.GetValue(Object obj,Object [] index)中的BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化) System.Data.Objects.ELinq.ELinqQueryState上的System.Data.Objects.ELinq.QueryParameterExpression.EvaluateParameter(Object [] arguments)中的System.Data.Objects.ELinq.QueryParameterExpression.TryEvaluatePath(Expression expression,ConstantExpression&constantExpression)中的Object&memberValue) .GetExecutionPlan(Nullable 1 forMergeOption) at System.Data.Objects.ObjectQuery1.GetResults(Nullable 1 forMergeOption) at System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable.GetEnumerator()在System.Linq.Enumerable.FirstOrDefault [T 来自 …

c# asp.net-mvc entity-framework asp.net-mvc-3 entity-framework-5

222
推荐指数
5
解决办法
20万
查看次数

EF非静态方法需要目标

我对以下查询存在严重问题.

context.CharacteristicMeasures
        .FirstOrDefault(cm => cm.Charge == null &&
                              cm.Characteristic != null &&
                              cm.Characteristic.Id == c.Id &&
                              cm.Line != null &&
                              cm.Line.Id == newLine.Id &&
                              cm.ShiftIndex != null &&
                              cm.ShiftIndex.Id == actShiftIndex.Id &&
                              (newAreaItem == null ||
                                  (cm.AreaItem != null &&
                                   cm.AreaItem.Id == newAreaItem.Id)));
Run Code Online (Sandbox Code Playgroud)

TargetException: Non-static method requires a target 当newAreaItem为null时,我得到一个.如果newAreaItem不为null,我得到一个NotSupportedException: Unable to create a constant value of type 'PQS.Model.AreaItem'. Only primitive types or enumeration types are supported in this context.

我已经检查过它们是否为null:c,newLine,actShiftIndex所有3个变量都不为空且可以访问Id.

我不明白......请帮忙.

如果你需要更多信息..不要犹豫,问...

UPDATE

我可以消除NotSupportedException,但是当newAreaItemIsNull为true时我仍然得到了TargetException ..:/

bool …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework

14
推荐指数
1
解决办法
4万
查看次数

非静态方法需要目标

private PMS_USERS currUser;
private bool validateUserName()
{
    dbContext = new PmsEntities();
    var validateUser = dbContext.PMS_USERS.Where(p=> p.LOGICALREF != currUser.LOGICALREF).Where(p=> p.USERNAME == currUser.USERNAME);
    return !validateUser.Any();
}
Run Code Online (Sandbox Code Playgroud)

您好,我在新用户注册表单上验证时出错.

我的PMS_USERS桌子没有记录(null).我也试过检查null控件currUser.

我错过了什么?

错误是:

非静态方法需要目标

c# asp.net entity-framework

5
推荐指数
1
解决办法
3万
查看次数