c# - Automapper fails to map two entities -
i'm trying map 2 entities - productpicturedto productpicturebdo - using automapper, exception , i'm not able understand thew mistake.
the error
missing type map configuration or unsupported mapping.
mapping types: productpicturedto -> guid erp.dto.products.productpicturedto -> system.guid
destination path: productpicturebdo
source value: erp.dto.products.productpicturedto
here below can see productpicturedto
[datacontract] public class productpicturedto { [datamember] public guid productpictureid { get; private set; } [datamember] public byte[] image { get; set; } [datamember] public guid productid { get; set; } [datamember] public virtual productdto product { get; set; } }
here below properties of productpicturebdo
public class productpicturebdo : ientity<productpicturebdo>, ivalidation { public const string picture_content_not_valid_error_message = "picture: content of picture not valid"; public const string associated_product_not_valid_error_message = "picture: picture not associated product"; public productpicturebdo(guid id) { productpictureid = id; } public guid productpictureid { get; private set; } public byte[] image { get; set; } public bool deleted { get; private set; } #region navigation properties public virtual productbdo product { get; set; } public guid productid { get; set; } }
here below method tries map 2 entities
public ienumerable<ierror> validateproductpicture(productpicturedto picture) { return _productsmanager.validateproductpicture(productsmapper.convert<productpicturedto, productpicturebdo>(picture)); }
here below class responsible mapping
public static class productsmapper { static productsmapper() { mapproductbdotodto(); mapproductdtotobdo(); mapproductcategorybdotodto(); mapproductcategorydtotobdo(); mapivabdotodto(); mapivadtotobdo(); mapproductsupplierbdotodto(); mapproductsupplierdtotobdo(); mapproductpicturebdotodto(); mapproductpicturedtotobdo(); mapproductnotebdotodto(); mapproductnotedtotobdo(); mapstockproductbdotodto(); mapstockproductdtotobdo(); maptagbdotodto(); maptagdtotobdo(); } public static ttargettype convert<ttoconvert, ttargettype>(ttoconvert toconvert) { return mapper.map<ttargettype>(toconvert); } private static void mapproductdtotobdo() { mapper.createmap<productdto, productbdo>(); } private static void mapproductbdotodto() { mapper.createmap<productdto, productbdo>().reversemap(); } private static void mapproductcategorydtotobdo() { mapper.createmap<productcategorydto, productcategorybdo>(); } private static void mapproductcategorybdotodto() { mapper.createmap<productcategorybdo, productcategorydto>(); } private static void mapivadtotobdo() { mapper.createmap<ivadto, ivabdo>(); } private static void mapivabdotodto() { mapper.createmap<ivabdo, ivadto>(); } private static void mapproductsupplierdtotobdo() { mapper.createmap<productsupplierdto, productsupplierbdo>(); } private static void mapproductsupplierbdotodto() { mapper.createmap<productsupplierdto, productsupplierbdo>().reversemap(); } private static void mapproductpicturedtotobdo() { mapper.createmap<productpicturedto, productpicturebdo>(); } private static void mapproductpicturebdotodto() { mapper.createmap<productpicturedto, productpicturebdo>().reversemap(); } private static void mapproductnotedtotobdo() { mapper.createmap<productnotedto, productnotebdo>(); } private static void mapproductnotebdotodto() { mapper.createmap<productnotedto, productnotebdo>().reversemap(); } private static void mapstockproductdtotobdo() { mapper.createmap<stockproductdto, stockproductbdo>(); } private static void mapstockproductbdotodto() { mapper.createmap<stockproductdto, stockproductbdo>().reversemap(); } private static void maptagdtotobdo() { mapper.createmap<tagdto, tagbdo>(); } private static void maptagbdotodto() { mapper.createmap<tagdto, tagbdo>().reversemap(); } }
i exception in method convert of class productmapper
wild try : use mapper.dynamicmap instead of mapper.map (m risking down votes here!!)
Comments
Post a Comment