Automapping properties assistance required
-
I am currently working with a DB table and I need to map extra properties from DAO to BE class. I have to produce XML like the following:
234OI456
The Zoo3456 Kramer
92345-8922
CobraThe extra columns in the db view are like so: ANI_TYPE VARCHAR(20) ANI_VALUE VARCHAR(20) Previously when I didn't have the extra columns I mapped the values like this for each Zoo
Mapper.CreateMap()
.ForMember(d => d.ZooId, e => e.ZOO_ID))
.ForMember(d => d.Name, e => e.ZOO_NAME))
.ForMember(d => d.Address, e => e.ZOO_ADDRESS))
.ForMember(d => d.ZipCode, e => e.ZOO_ZIPCODE));How would I go about mapping these 2 columns(ANI_TYPE, ANI_VALUE) so i can create the structure shown in the xml in regards to Animals? I have a c# class for Animal type which has the following
public enum AnimalType
{
INVALID,
REPTILE,
MAMMAL,
INSECT
}My C# class for the Animal looks like this but i guess it will require rework. Feel free to provide suggestions/examples: Currently this is what my classes look like:
//BE class
public class Zoo
{
public int ZooId {get; set;}
public string Name { get; set; }
public string Address {get; set; }
public string ZipCode {get; set;}
public List Animals {get; set;}
}This is my current setup for Animal entity
//BE Class
public class Animal
{
public string Type {get; set;}
public string Text { get; set; }
}I appreciate if someone can assist me with the above. Thanks,
-
I am currently working with a DB table and I need to map extra properties from DAO to BE class. I have to produce XML like the following:
234OI456
The Zoo3456 Kramer
92345-8922
CobraThe extra columns in the db view are like so: ANI_TYPE VARCHAR(20) ANI_VALUE VARCHAR(20) Previously when I didn't have the extra columns I mapped the values like this for each Zoo
Mapper.CreateMap()
.ForMember(d => d.ZooId, e => e.ZOO_ID))
.ForMember(d => d.Name, e => e.ZOO_NAME))
.ForMember(d => d.Address, e => e.ZOO_ADDRESS))
.ForMember(d => d.ZipCode, e => e.ZOO_ZIPCODE));How would I go about mapping these 2 columns(ANI_TYPE, ANI_VALUE) so i can create the structure shown in the xml in regards to Animals? I have a c# class for Animal type which has the following
public enum AnimalType
{
INVALID,
REPTILE,
MAMMAL,
INSECT
}My C# class for the Animal looks like this but i guess it will require rework. Feel free to provide suggestions/examples: Currently this is what my classes look like:
//BE class
public class Zoo
{
public int ZooId {get; set;}
public string Name { get; set; }
public string Address {get; set; }
public string ZipCode {get; set;}
public List Animals {get; set;}
}This is my current setup for Animal entity
//BE Class
public class Animal
{
public string Type {get; set;}
public string Text { get; set; }
}I appreciate if someone can assist me with the above. Thanks,
-
Have you tried to create a mapping from
AnimalDAO
toAnimalBE
? Like you're doing here:Mapper.CreateMap()
.ForMember( etc.. )That should be all it needs if your AnimalDAO(edit) ZooDAO class also holds the Animals in some type of collection. Take a look here[^] - he's essentially doing the same.