Only parameterless constructors and initializers are supported in LINQ to Entities
2009-08-10 16:43
656 查看
近期开发过程中,使用Entity Framework时,在对一个实体通过主键(GUID类型)查询时,出现“Only parameterless constructors and initializers are supported in LINQ to Entities”错误,代码如下:
var roles = from r in entites.Roles
where r.RoleId == new Guid(roleId)
select r;
而var roles = from r in entites.Roles
where r.RoleId == new Guid(“fe3f46fd-b85a-42f5-a490-fd76e249f045”)
select r;
这样则没有问题,我仔细对比了roleId的值,实在是没发现问题,最终google出两篇文章还算可以:
http://blog.miniasp.com/?tag=/linq+to+entity
http://geekswithblogs.net/SudheersBlog/archive/2009/06/11/132758.aspx
链接2指出问题的关键:有些CLR方法当前并不能转化为规范的表达式树方法(翻译的不当:Certain CLR methods are converted to command tree canonical functions, which can be executed on the database. If a CLR method cannot be mapped to a command tree canonical function, an exception will be thrown when translation occurs.),反正内意思就是有些不支持,就是不能用,哈哈。
微软提供了一个可用CLR方法的列表《CLR Method to Canonical Function Mapping》,链接:
http://msdn.microsoft.com/en-us/library/bb738681.aspx
var roles = from r in entites.Roles
where r.RoleId == new Guid(roleId)
select r;
而var roles = from r in entites.Roles
where r.RoleId == new Guid(“fe3f46fd-b85a-42f5-a490-fd76e249f045”)
select r;
这样则没有问题,我仔细对比了roleId的值,实在是没发现问题,最终google出两篇文章还算可以:
http://blog.miniasp.com/?tag=/linq+to+entity
http://geekswithblogs.net/SudheersBlog/archive/2009/06/11/132758.aspx
链接2指出问题的关键:有些CLR方法当前并不能转化为规范的表达式树方法(翻译的不当:Certain CLR methods are converted to command tree canonical functions, which can be executed on the database. If a CLR method cannot be mapped to a command tree canonical function, an exception will be thrown when translation occurs.),反正内意思就是有些不支持,就是不能用,哈哈。
微软提供了一个可用CLR方法的列表《CLR Method to Canonical Function Mapping》,链接:
http://msdn.microsoft.com/en-us/library/bb738681.aspx
相关文章推荐
- The specified type member 'IsLock' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
- The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
- Laravel 出现"RuntimeException inEncrypter.php line 43: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths."问题的解决办法
- File /hbase could only be replicated to 0 nodes instead of minReplication (=1). There are 30 datanode(s) running and no node(s) are excluded in this operation.
- Comparison of user class objects is not supported in Linq to entities
- Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'. Parameter name: uri
- You are attempting to build on a 32-bit system.Only 64-bit build environments are supported beyond f
- The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
- Linq to Entities in Ado.net EF的事务
- LINQ To Entities如何实现查询 select * from tableA where id in (1,2,3,4) ?
- LINQ to Entities 实现sql 关键字"In"方式总结
- .NET错误The 'targetFramework' attribute in the <compilation> element of the Web.config file is used only to target version 4.0 and later of the .NET Framework
- how to select data in multiple datatables after using join,group by and order by in Linq
- 关于.ToList(): LINQ to Entities does not recognize the method ‘xxx’ method, and this method cannot be translated into a store expression.
- Introduction to Constructors and Destructors in VB.NET
- LINQ to Entities 实现sql 关键字"In"方式总结
- Update on LINQ to SQL and LINQ to Entities Roadmap [ 关注 ]
- Join and Group By with LINQ to Entities
- Question 12: In C++, which of the following is the best declaration for an overloaded operator[] to allow read-only access (and
- How to solve problem caused when the CRT library and MFC libraries are linked in the wrong order