locked
Key, Value pairs implementation in class RRS feed

  • Question

  • User1176145865 posted

    Hi

    In a project im working on there are many sql tables containing different ID, Name pairs. Those are represented as Enums in classes that need them however that requires casting since tables contain ID only.

    Also when serialize the Enum contains the ID not value.



    Tuesday, February 16, 2010 4:48 AM

Answers

  • User1176145865 posted

    Hi

    Found a way to bypass the casting issue by returning complex objects using a stored procedure 

    IEnumerable<MyTeamResults> mtr = MyEntities.GetTeamResults();


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 17, 2010 6:50 AM

All replies

  • User-952121411 posted

    Could you please repost your question with some more detail, so we can help with some ideas?  Are you trying to figure out how to get the value extracted from an enum so you can map it to your database values.  If you could provide some coding examples, that would help as well.

    Thank you,

    Tuesday, February 16, 2010 9:59 AM
  • User1176145865 posted

    Hi,

    Thank you for the answer.

    Here is an example:

    I have a class 'Team' that holds the following properties represented by Enums:

    class Team
    
    {
    
    //enums:
    
    public TeamPressure perssure { get;set;}
    
    public PlayStyle style { get;set;}
    
    }



    Using Enums requires casting when instanciating a new Team and again on save:

    Get();
    
    using (MyEntities....
    
    this.perssure = (TeamPressure)team.PressureID
    
    
    Save();
    
    team.PressureID = (int)this.perssure;



    Another issue is when Serialized only the Enum ID is used and the value has to retrive separatly.



    Tuesday, February 16, 2010 11:43 AM
  • User1176145865 posted

    Hi

    Found a way to bypass the casting issue by returning complex objects using a stored procedure 

    IEnumerable<MyTeamResults> mtr = MyEntities.GetTeamResults();


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 17, 2010 6:50 AM