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