LINQ2SQL 在读取记录列表时切换到 EF
我正在尝试从 LINQ2SQL 切换到 EF ...我收到一些最初与 LINQ2SQL 一起使用的代码,并且似乎可以正确编译,但出现以下错误: <代码>
<代码>Csla.DataPortalException: DataPortal.Fetch 失败(LINQ to 实体无法识别该方法 'MyApp.Logic.UserInfo FetchUserInfo(MyApp.Data.User)' 方法,并且该方法不能 翻译成商店表达式。)
---> Csla.Reflection.CallMethodException: DataPortal_Fetch方法调用失败
---> System.NotSupportedException:LINQ to Entities 无法识别 方法“MyApp.Logic.UserInfo” FetchUserInfo(MyApp.Data.User)' 方法,并且该方法不能 翻译...
这是代码:
var data = query.Select(row => UserInfo.FetchUserInfo(row));
this.AddRange(data);
我正在尝试读取数据列表并将实体加载到我的类中。我是 EF 的新手,只是觉得我忽略了一些事情。
任何帮助将不胜感激!
对于那些感兴趣的人,解决方案是:
var data = query.AsEnumerable().Select(UserInfo.FetchUserInfo);
I am trying to switch from LINQ2SQL to EF ... I am getting the following error with some code that originally worked with LINQ2SQL and seems to compile correctly:
Csla.DataPortalException:
DataPortal.Fetch failed (LINQ to
Entities does not recognize the method
'MyApp.Logic.UserInfo
FetchUserInfo(MyApp.Data.User)'
method, and this method cannot be
translated into a store expression.)---> Csla.Reflection.CallMethodException:
DataPortal_Fetch method call failed---> System.NotSupportedException: LINQ to Entities does not recognize
the method 'MyApp.Logic.UserInfo
FetchUserInfo(MyApp.Data.User)'
method, and this method cannot be
translat...
This is the code:
var data = query.Select(row => UserInfo.FetchUserInfo(row));
this.AddRange(data);
I'm trying to read a list of data and load the entities into my class. I'm new to EF and just think I am overlooking something.
Any help would be appreciated!
For those interested, the solution was:
var data = query.AsEnumerable().Select(UserInfo.FetchUserInfo);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,问题在于 Linq to Entities 提供程序对如何将自定义方法
FetchUserInfo
转换为 ESQL 一无所知。如果
UserInfo
只是一个 DTO,并且UserInfo.FetchUserInfo
是一种实体到 DTO 转换方法,这将有助于.AsEnumerable()
调用将查询
结果具体化为内存对象。As far as I can see the problem is that Linq to Entities provider knows nothing about how to translate you custom method
FetchUserInfo
to ESQL.If
UserInfo
is just a DTO andUserInfo.FetchUserInfo
is a kind of Entity to DTO conversion method this would help.AsEnumerable()
invoke will result in materialization ofquery
results to memory objects.