无法创建“System.Object”类型的常量值。在此上下文中仅支持基本类型(如Int32,String和Guid) [英] Unable to create a constant value of type 'System.Object'. Only primitive types ('such as Int32, String, and Guid') are supported in this context

查看:742
本文介绍了无法创建“System.Object”类型的常量值。在此上下文中仅支持基本类型(如Int32,String和Guid)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC和实体框架。我在我的模型文件夹中创建了一个类,代码如下。我以前收到上面两个查询的错误信息。我知道引用非标量变量有一个已知的问题,但我不知道如何实现一个解决方法:



http://msdn.microsoft.com/en-us/library/bb896317.aspx#Y1442

  private MovieLibraryDBEntities movieLibraryDBEntitiesContext; 

public int getNumberOfEntriesReserved()
{
return(from m in movieLibraryDBEntitiesContext.Movies
where m.CheckedOut.Equals(1)
select m) 。计数(); $ e
// return .title伪).Count之间();
}


解决方案

您不能使用 m.CheckedOut.Equals(1)在linq-to-entities查询中。使用 m.CheckedOut == 1 CheckedOut 必须是整数


I'm using MVC and Entity Framework. I've created a class in my model folder with this code below. I keep getting the error message above with both queries below. I know there is a known issue on referencing non-scalar variables, but I'm not sure how to implement a workaround:

http://msdn.microsoft.com/en-us/library/bb896317.aspx#Y1442

private MovieLibraryDBEntities movieLibraryDBEntitiesContext;

public int getNumberOfEntriesReserved()
{
    return (from m in movieLibraryDBEntitiesContext.Movies
            where m.CheckedOut.Equals(1)
            select m).Count();

    //return movieLibraryDBEntitiesContext.Movies
    //  .Where(e => e.CheckedOut.Equals(1))
    //  .Select (e => e.Title).Count();
}

解决方案

You cannot use m.CheckedOut.Equals(1) in linq-to-entities query. Use m.CheckedOut == 1 but CheckedOut must be integer.

这篇关于无法创建“System.Object”类型的常量值。在此上下文中仅支持基本类型(如Int32,String和Guid)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆