-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Mapping custome enum-like class based on struct
PostPosted: Fri Jul 11, 2008 11:54 pm 
Newbie

Joined: Fri Jul 11, 2008 11:39 pm
Posts: 7
Hi,
i had a need to create enum like classes for lookup tables that all have these fields: id, code, name, description.

.NET2.0 enums do not easily support such a thing. So what i did was "faked" it using code much like the one below (which i created a CodeSmith template for). I am new to NHibernate and would like to know how i map such classes to their tables using NHibernate?


Code:

using System;

namespace LookUpTypes
{
    /// <summary>
    /// An enum representation of the 'StatusType' table. [No description found in the database]
    /// </summary>
    /// <remark>this struct is uses the items contained in the table StatusType</remark>
    [Serializable]
    public struct StatusType
    {
        public int Id;  //should map to id field in StatusType table
        public string Code; //should map to code field in StatusType table
        public string Name; //should map to name field in StatusType table
        public string Description; //should map to description field in StatusType table

        private StatusType(int id, string code, string name, string descr)
        {
            this.Id = id;
            this.Code = code;
            this.Name = name;
            this.Description = descr;

        }

        public static StatusType SUBMITTED = new StatusType(1000, "SUBMITTED", "Submitted", "WorkItem Submitted");
        public static StatusType APPROVED = new StatusType(1010, "APPROVED", "Approved", "WorkItem Approved");
        public static StatusType REJECTED = new StatusType(1020, "REJECTED", "Rejected", "WorkItem Rejected");
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 10:52 pm 
Newbie

Joined: Fri Jul 11, 2008 11:39 pm
Posts: 7
Hi,
is the above not possible?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.