1

次のコードがあります

return (_entities.Users.Select(profile => new ProfileUserListItemDto
                {
                    Email = profile.Email,
                    FirstName = profile.FirstName,
                    Id = profile.Id,
                    LastName = profile.LastName,
                    Role = DtoEntityLookups.EntityRoleToDtoRole(profile.Role),
                    TimeZone = profile.TimeZone
                })).ToList();

public static RoleTypeEnum EntityRoleToDtoRole(Role role)
        {
            if (role == null)
                throw new NoNullAllowedException("Null role supplied to EntityRoleToDtoRole method");

            if (role.Id.ToString() == RolesGuid.AdministratorGuid)
                return RoleTypeEnum.Administrator;
            if (role.Id.ToString() == RolesGuid.ClientGuid)
                return RoleTypeEnum.Client;

            throw new InvalidDataException("Unknown role supplied");
        }

呼び出されると、次のエラーが表示されます

LINQ to Entities は RoleTypeEnum EntityRoleToDtoRole(User.Entities.Entities.Role) メソッドを認識せず、このメソッドはストア式に変換できません。

EntityRoleToDtoRoleを Entity Framework クエリから呼び出し可能に変換するにはどうすればよいですか?

4

1 に答える 1

2

linq 内でメソッドを呼び出して呼び出すには、Users.AsEnumerable() を使用する必要があります。

return (_entities.Users.AsEnumerable().Select(profile => new ProfileUserListItemDto
                {
                    Email = profile.Email,
                    FirstName = profile.FirstName,
                    Id = profile.Id,
                    LastName = profile.LastName,
                    Role = DtoEntityLookups.EntityRoleToDtoRole(profile.Role),
                    TimeZone = profile.TimeZone
                })).ToList();
于 2013-04-10T13:52:39.197 に答える