1

I'm using AutoMapper to map my Entity to my DTO. I have a property which compares two lists in my entity and return true or false if equal.

public bool AreAllEmployeesInformed
    {
        get
        {
            var result = (from a in Employees
                join b in EmployeesInformed on a.Id equals b.Id
                select a).Count();

            if ((result == Employees.Count) && (result == EmployeesInformed.Count))
                return true;
            return false;

        }
    }

This is my mapping config

MappingConfiguration.CreateMap<Entities.Action, ForeManListItemDto>()
            .ForMember(x => x.Informed, x => x.MapFrom(y=>y.Activity.AreAllEmployeesInformed))

I want to map this to my DTO as true or false, but AutoMapper refuses. How can I fix this?

The error it gives me is "The specified type member 'Activity' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

Thanks in advance.

Nicolas Zawada
  • 497
  • 1
  • 3
  • 12
  • Can you show the relevant CreateMap code, and how it fails? – stuartd Mar 15 '16 at 09:53
  • This looks like [an EF problem](http://stackoverflow.com/questions/6919709/only-initializers-entity-members-and-entity-navigation-properties-are-supporte) rather than an AutoMapper one. – stuartd Mar 15 '16 at 10:11
  • Are you calling Mapper.Map or ProjectTo? And I shudder to think what the SQL that little snippet is generating if it's using EF lazy loading. – Jimmy Bogard Mar 15 '16 at 16:31

1 Answers1

0

Just rename the both property to Informed and it will be mapped probably. If you don't would like to, I tried it as a method and it works for me For instance: change:

public bool AreAllEmployeesInformed
    {
        get
        {
            var result = (from a in Employees
                join b in EmployeesInformed on a.Id equals b.Id
                select a).Count();

            if ((result == Employees.Count) && (result == EmployeesInformed.Count))
                return true;
            return false;

        }
    }

to :

public bool AreAllEmployeesInformed()
    {
        get
        {
            var result = (from a in Employees
                join b in EmployeesInformed on a.Id equals b.Id
                select a).Count();

            if ((result == Employees.Count) && (result == EmployeesInformed.Count))
                return true;
            return false;

        }
    }