1
public class MyClassA
{
    int Id { get; set; }
    string Name { get; set; }

    int MyClassBId { get; set; }
    int MyClassCId { get; set; }
}

public class MyClassB
{
    int Id { get; set; }
}

public class MyClassC
{
    int Id { get; set; }
}

I do a join :

using (var context = GetNewContext())
{
    var liste =
        (from myA in context.MyClassA
         join myB in context.MyClassB on myA.MyClassBId equals myB.Id
         join myC in context.MyClassC on myA.MyClassCId equals myC.Id
         select MyClassA).ToList<MyClassA>();

    return Mapper.Map<IList<MyClassA>, List<MyOtherClassA>>(liste);
}

I get this exception on the return :

Missing type map configuration or unsupported mapping.
_FB2F4E3BBB925EC65C0AE58F6566366E06009C68B4A2C1C12EE401E77A489D87 -> IMyClassB
System.Data.Entity.DynamicProxies.SITE_FB2F4E3BBB925EC65C0AE58F6566366E06009C68B4A2C1C12EE401E77A489D87

The mapping is :

Mapper.CreateMap<MyClassA, MyOtherClassA>()
    .ForMember(x => x.MyClassB, opt => opt.Ignore())
    .ForMember(x => x.MyClassC, opt => opt.Ignore());

Other problem(?) ... when I try to insert, I have to do this :

var newA = Mapper.Map<MyOtherClassA, MyClassA>(newA);
newA.MyClassB = null;
newA.MyClassC = null;

context.MyClassA.Add(newA);
context.SaveChanges();
TheBoubou
  • 19,487
  • 54
  • 148
  • 236
  • This looks like the same problem as [here](http://stackoverflow.com/questions/13416816/how-to-update-an-existing-entity-from-viewmodel-using-automapper-and-ef4-dbconte) and also have a look at SubKamrans answer to [this](http://stackoverflow.com/questions/3441916/automapper-mapping-issue-with-inheritance-and-abstract-base-class-on-collectio) – StuartLC Nov 30 '12 at 11:34
  • Take a look at this question: http://stackoverflow.com/questions/3441916/automapper-mapping-issue-with-inheritance-and-abstract-base-class-on-collectio , the similar issue. – Dennis Nov 30 '12 at 11:34
  • Just a thought, are you writing out your POCO proxy classes and Mapping yourself? Are you aware of the DbContext Generator that will generate your POCO's for you and have EF handle the mapping internally? http://visualstudiogallery.msdn.microsoft.com/7812b04c-db36-4817-8a84-e73c452410a2 – SimonGates Nov 30 '12 at 11:35
  • @coding-ninja: this generator is intended for *model-first* approach, *code-first* approach means writing entity classes and (possibly), mappings manually. In addition, how your comment is related to question? – Dennis Nov 30 '12 at 11:45
  • What is `MyOtherClassA`? (Is it the same as `MyClassA` or does it have different properties?) – Mightymuke Nov 30 '12 at 20:10

0 Answers0