LINQ2SQL switch to EF on reading a list of records

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

Answers


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.


Need Your Help

Animating the transition from Pressed to Normal button state

wpf xaml windows-phone-8

My Pressed state is lowering the opacity of the Button content.

problem with replacing a background image using signal / slot in qt

qt background signals-slots qtablewidget

i want to make a simple chess program. So far i've made the board using QTableWidget and loaded the piece pictures in the cells of table. Now i wnat to use signal and slot so that when user clicks ...