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; }
}
我加入了:
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);
}
我在返回时遇到此异常:
Missing type map configuration or unsupported mapping.
_FB2F4E3BBB925EC65C0AE58F6566366E06009C68B4A2C1C12EE401E77A489D87 -> IMyClassB
System.Data.Entity.DynamicProxies.SITE_FB2F4E3BBB925EC65C0AE58F6566366E06009C68B4A2C1C12EE401E77A489D87
映射是:
Mapper.CreateMap<MyClassA, MyOtherClassA>()
.ForMember(x => x.MyClassB, opt => opt.Ignore())
.ForMember(x => x.MyClassC, opt => opt.Ignore());
其他问题(?)......当我尝试插入时,我必须这样做:
var newA = Mapper.Map<MyOtherClassA, MyClassA>(newA);
newA.MyClassB = null;
newA.MyClassC = null;
context.MyClassA.Add(newA);
context.SaveChanges();