0

I have the following code:

 Expression<Func<int, string>> myStatusCode = (t) =>  PluginApplication.Types.ToTypeName(t); 
        var model =_context.UsersRepository.Include("Emails").Include("Website").
                        Include("UserDetail").Include("Profile").AsExpandable().Where(t => t.TypeId == (UserType)10017).Select(t=> new
                    {
                        UserId = t.UserId,
                        UserName = t.UserName,
                        ChatName = t.ChatName,
                        Email = t.Emails.FirstOrDefault(z => z.TypeId == EmailType.Main).EmailAddress,
                        LastLoginDate = t.LastLoginDate,
                        StatusId = t.StatusId,
                        Website = t.SignedUpOnWebsite.ShortName,
                        StatusCode = myStatusCode.Invoke((int)t.StatusId)

                    });

Here I'm using LinqKit which seems to help me call a method when select some data without Take expresion AsEnumerable.If I put ToList or AsEnumerable , will work well, but I don't wanna do this.I want to find something to avoid the error :

LINQ to Entities does not recognize the method'PluginApplication.Types.ToTypeName (System.Int32)' method, and this method cannot be translated into a store expression.

user_1856538_
  • 149
  • 11
  • How do you expect EF to translate your expression into sql? – David L Aug 19 '15 at 15:27
  • You could make a class to hold that data including the status id and it could also have a `StatusCode` property that just calls that method to translate the status id. – juharr Aug 19 '15 at 15:28
  • Just use `AsEnumerable()` before the select, not sure why you don't want to use it, it is the correct thing in this case, it is just telling EF not to try and convert the select into SQL which is exactly what you want. – Ben Robinson Aug 19 '15 at 15:28
  • This is a query for a grid with 10000+ rows.As I know (maybe I'm wrong) , using AsEnumerable(), take all data and put them in memory.I don't want to have this effect each time when I access a new grid page...I think I will have some performance issues. – user_1856538_ Aug 19 '15 at 15:44

0 Answers0