您的位置:首页 > 其它

Only parameterless constructors and initializers are supported in LINQ to Entities

2009-08-10 16:43 597 查看
近期开发过程中,使用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐