Q:

Mapping entities to DTOs

I have an EF Entity that i want to map its attributes to a DTO with a function while using the fluent syntax.
Take the User for example I was able to make it work mapping it this way:
    public Task<List<JournalTransactionModel>> GetAllJournalRecords()
    {
        var journalRecords = db.JournalTransactions
            .Include(_ => _.JournalTransactionsAccounts)
            .Include(_ => _.User)
            .Select(_ => new JournalTransactionModel
            {
                JournalTransactionId = _.JournalTransactionId,
                Date = _.Date,
                Description = _.Description,
                User = new UserModel
                {
                    UserId = _.UserId,
                    FirstName = _.User.FirstName,
                    LastName = _.User.LastName,
                    FullName = _.User.FirstName + " " + _.User.LastName,
                    Email = _.User.Email,
                    UserName = _.User.UserName,
                    Password = _.User.Password,
                    UserRoleAndPermissions = new UserRoleModel
                    {
                        UserRoleId = _.User.UserRole.UserRoleId,
                        UserRoleName = _.User.UserRole.UserRoleName,
                        CanRead = _.User.UserRole.CanRead,
                        CanWrite = _.User.UserRole.CanWrite
                    }
                },
                TransactionAccounts = _.JournalTransactionsAccounts.Select(j => new JournalTransactionAccountModel
                {
                    JournalTransactionAccountId = j.Id,
                    JournalTransactionId = j.JournalTransactionId,
                    DebitAccount = j.DebitAccount != null ? new AccountModel
                    {
                        AccountId = j.DebitAccount.AccountId,
                        AccountCategoryName = j.DebitAccount.AccountCategory.AccountCategoryName,
                        AccountCategoryId = j.DebitAccount.AccountCategoryId,
                        AccountName = j.DebitAccount.AccountName,
                        IncreasesWhenDebited = j.DebitAccount.IncreasesWhenDebited
                    } : null,
                    CreditAccount = j.CreditAccount != null ? new AccountModel
                    {
                        AccountId = j.CreditAccount.AccountId,
                        AccountCategoryName = j.CreditAccount.AccountCategory.AccountCategoryName,
                        AccountCategoryId = j.CreditAccount.AccountCategoryId,
                        AccountName = j.CreditAccount.AccountName,
                        IncreasesWhenDebited = j.CreditAccount.IncreasesWhenDebited
                    } : null,
                    Amount = j.Amount,
                    Person = j.Person != null ? new PersonModel
                    {
                        PersonId = j.PersonId,
                        FirstName = j.Person.FirstName,
                        LastName = j.Person.LastName,
                        FullName = j.Person.FirstName + " " + j.Person.LastName,
                        Email = j.Person.Email,
                        SocialSecurityNumber = j.Person.SocialSecurityNumber,
                        PersonType = new PersonTypeModel
                        {
                            Id = j.Person.PeopleType.PeopleTypeId,
                            Name = j.Person.PeopleType.Name
                        }
                    } : null
                }).ToList()
            }).ToListAsync();
        return journalRecords;
    }

But when i tried to Create a function that returns UserModel I kept getting exceptions
    public Task<List<JournalTransactionModel>> GetAllJournalRecords()
    {
        var journalRecords = db.JournalTransactions
            .Include(_ => _.JournalTransactionsAccounts)
            .Include(_ => _.User)
            .Select(_ => new JournalTransactionModel
            {
                JournalTransactionId = _.JournalTransactionId,
                Date = _.Date,
                Description = _.Description,
                User = MapUserToModel(_.User),
                TransactionAccounts = _.JournalTransactionsAccounts.Select(j => new JournalTransactionAccountModel
                {
                    JournalTransactionAccountId = j.Id,
                    JournalTransactionId = j.JournalTransactionId,
                    DebitAccount = j.DebitAccount != null ? new AccountModel
                    {
                        AccountId = j.DebitAccount.AccountId,
                        AccountCategoryName = j.DebitAccount.AccountCategory.AccountCategoryName,
                        AccountCategoryId = j.DebitAccount.AccountCategoryId,
                        AccountName = j.DebitAccount.AccountName,
                        IncreasesWhenDebited = j.DebitAccount.IncreasesWhenDebited
                    } : null,
                    CreditAccount = j.CreditAccount != null ? new AccountModel
                    {
                        AccountId = j.CreditAccount.AccountId,
                        AccountCategoryName = j.CreditAccount.AccountCategory.AccountCategoryName,
                        AccountCategoryId = j.CreditAccount.AccountCategoryId,
                        AccountName = j.CreditAccount.AccountName,
                        IncreasesWhenDebited = j.CreditAccount.IncreasesWhenDebited
                    } : null,
                    Amount = j.Amount,
                    Person = j.Person != null ? new PersonModel
                    {
                        PersonId = j.PersonId,
                        FirstName = j.Person.FirstName,
                        LastName = j.Person.LastName,
                        FullName = j.Person.FirstName + " " + j.Person.LastName,
                        Email = j.Person.Email,
                        SocialSecurityNumber = j.Person.SocialSecurityNumber,
                        PersonType = new PersonTypeModel
                        {
                            Id = j.Person.PeopleType.PeopleTypeId,
                            Name = j.Person.PeopleType.Name
                        }
                    } : null
                }).ToList()
            }).ToListAsync();
        return journalRecords;

What is wrong up there?
This is the message I get:

"ExceptionMessage": "LINQ to Entities does not recognize the method 'ACS.Hub.BusinessLogic.Models.UserModel MapUserToModel(ACS.Hub.Repository.User)' method, and this method cannot be translated into a store expression."

A:

LINQ query expression translated on server IQueryable query. In your case are not supported because your subQuery must be calculate on memory. MapUserToModel method want to use calculated data. If you want to fill user propery by MapUserToModel method  you can get data on memory using by ToList() before Select data.
var journalRecords = db.JournalTransactions
            .Include(_ => _.JournalTransactionsAccounts)
            .Include(_ => _.User)
            .ToList()
            .Select(_ => new JournalTransactionModel
            {
              ....
            }

