c# - Flatten/Unflatten data from Entities to Models with AutoMapper -
i flatten/unflatten classes using automapper, not sure if possible. have listdefo , valuedefo, how list , values defined. user can add them data object. not worried storing valuedefo id against datavalue, need string value. here classes
public class listdefo { public long id { get; set; } public virtual icollection<valuedefo> values { get; set; } } public class valuedefo { public long id { get; set; } public string value { get; set; } } public class data { public long id { get; set; } public icollection<datavalue> values { get; set; } } public class datavalue { public long id { get; set; } public virtual listdefo listdefo { get; set; } public string value { get; set; } }
currently if use automapper, have following models, data object values property, , each datavalue have id, listdefoid , value.
public class datamodel { public long id { get; set; } public icollection<datavaluemodel> values { get; set; } } public class datavaluemodel { public long id { get; set; } public long listid { get; set; } public string value{ get; set; } }
this fine suppose, thought cleaner, if instead data object has list of lists, each list has values. this
public class datamodel { public long id { get; set; } public icollection<datalistmodel> lists { get; set; } } public class datalistmodel { public long id { get; set; } public string name { get; set; } public icollection<datavaluemodel> values { get; set; } } public class datavaluemodel { public long id { get; set; } public string value{ get; set; } }
is possible using automapper? again well
i if changed entities store data models, pointless have list record links data record , value records
you can use custom mapping/resolvers flatten/unflatten classes automapper, more hierarchy classes have more complex resolver be.
you can keep same hierarchy of models(dtos) remove properties think client shouldn't set, when want map-back original entity dto, can ignore these properties , map properties model (dto) has.
Comments
Post a Comment