0

我正在尝试从 LINQ2SQL 切换到 EF ...我收到以下错误,其中一些代码最初与 LINQ2SQL 一起使用并且似乎可以正确编译:

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...

这是代码:

var data = query.Select(row => UserInfo.FetchUserInfo(row));

this.AddRange(data);

我正在尝试读取数据列表并将实体加载到我的类中。我是 EF 的新手,只是觉得我忽略了一些东西。

任何帮助,将不胜感激!

对于那些感兴趣的人,解决方案是:

var data = query.AsEnumerable().Select(UserInfo.FetchUserInfo);
4

1 回答 1

2

FetchUserInfo据我所知,问题在于 Linq to Entities 提供者对如何将自定义方法转换为 ESQL一无所知。

如果UserInfo只是一个 DTO 并且UserInfo.FetchUserInfo是一种实体到 DTO 的转换方法,这将有所帮助

var data = query.AsEnumerable().Select(row => UserInfo.FetchUserInfo(row));

.AsEnumerable()调用将导致结果物化query到内存对象。

于 2010-07-06T05:48:32.873 回答