Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Automapping properties assistance required

Automapping properties assistance required

Scheduled Pinned Locked Moved C#
csharpdatabasexmlquestionworkspace
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eagle32
    wrote on last edited by
    #1

    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 Zoo

    3456 Kramer

    92345-8922
    Cobra

    The 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,

    L 1 Reply Last reply
    0
    • E Eagle32

      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 Zoo

      3456 Kramer

      92345-8922
      Cobra

      The 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,

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Which mapper are you using?

      E 1 Reply Last reply
      0
      • L Lost User

        Which mapper are you using?

        E Offline
        E Offline
        Eagle32
        wrote on last edited by
        #3

        I am using Automapper. Can you assist please? Thanks.

        L 1 Reply Last reply
        0
        • E Eagle32

          I am using Automapper. Can you assist please? Thanks.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Have you tried to create a mapping from AnimalDAO to AnimalBE ? 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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups