0

when i try to run the code

public static DalUser ToDalUser(this User ormUser)
    {
        return new DalUser()
        {
            Id = ormUser.Id,
            FirstName = ormUser.FirstName,
            LastName = ormUser.LastName,
            About = ormUser.About,
            Email = ormUser.Email,
            Password = ormUser.Password,
            Roles = ormUser.Roles.Select(role => role.ToDalRole())
        };
    }

error occurs

Additional information: LINQ to Entities does not recognize the method 'DAL.Interface.DTO.DalUser ToDalUser(ORM.User)' method, and this method cannot be translated into a store expression.

in View

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.FirstName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.LastName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Email)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.About)
        </td>
        <td>
            @Html.DisplayTextFor(modelItem => item.Role)
        </td>
    </tr>
}

what's the problem? please, help!

1 Answers1

0

Depending on how many Roles you have, if not that many you should be able to do this:

Roles = ormUser.Roles
  .ToArray()
  .Select(role => role.ToDalRole())

The reason being the ToArray() method will load all the Roles into memory before calling Select. If you have thousands (or even hundreds) this is not recommended.

mxmissile
  • 11,464
  • 3
  • 53
  • 79