我有以下代码:
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)
});
在这里,我使用的是LinqKit,它似乎可以帮助我在选择一些没有 Take expresion AsEnumerable 的数据时调用一个方法。如果我放 ToList 或 AsEnumerable ,效果会很好,但我不想这样做。我想找到一些可以避免的东西错误 :
LINQ to Entities 无法识别方法 'PluginApplication.Types.ToTypeName (System.Int32)' 方法,并且此方法无法转换为存储表达式。