开发者

LINQ2SQL switch to EF on reading a list of records

开发者 https://www.devze.com 2023-01-06 07:07 出处:网络
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:

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

开发者_StackOverflow中文版

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);


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 and UserInfo.FetchUserInfo is a kind of Entity to DTO conversion method this would help

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

.AsEnumerable() invoke will result in materialization of query results to memory objects.

0

精彩评论

暂无评论...
验证码 换一张
取 消