Kann jemand mir vorschlagen, wo ich den Fehler machte?Wie man ein Objekt einem anderen Objekt mit einigen Eigenschaften in einem Kindobjekt zuordnet
public class DataModelProduct
{
public int Id {get;set;}
public string Name {get;set;}
public string Price {get;set;};
public string Brand {get;set;}
public string Color {get;set;}
public string Dimentions {get;set;}
public string Type {get;set;}
public string Network {get;set;}
}
public class Product
{
public int Id {get;set;}
public string Name {get;set;}
public string Price {get;set;}
public Specification Spec {get;set;}
}
public class Specification
{
public string Brand {get;set;}
public string Color {get;set;}
public string Dimentions {get;set;}
public string Type {get;set;}
public string Network {get;set;}
}
AutoMapper.Mapper.CreateMap< DataModelProduct, Product>();
AutoMapper.Mapper.CreateMap< DataModelProduct, Specification>();
können Sie davon ausgehen, Product
Klasse Core-Modell ist und DataModelProduct
ist ein Datenbankmodell
Die Product
Eigenschaften zugeordnet werden, aber die Specification
Eigenschaft ist null.
Können Sie
Und Ihre Mapping-init-Code sollte so etwas wie
Und Ihre Laufzeitcode wie sein Deinen Mapping-Code hinzufügen? –
Rückgabe this.DB.SingleOrDefault ("Wobei ID = @ 0", ProductId) .MapTo (); –