typedef convention

Aaron Fischer's Avatar

Aaron Fischer

14 May, 2010 10:49 PM via web

Sorry I am a little lost with this. I have a class Email which I would like to see mapped as a string in the database with a specific length. Is there a simple way to set up this convention?

  1. Support Staff 2 Posted by Paul Batum on 17 May, 2010 04:49 AM

    Paul Batum's Avatar

    Can you give us a bit more info, such as what your domain model and schema look like? Your description isn't quite specific enough.

    Also, the conventions page on the wiki might help:
    wiki.fluentnhibernate.org/conventions

  2. 3 Posted by Aaron Fischer on 17 May, 2010 04:42 PM

    Aaron Fischer's Avatar

    class contact : BaseEntity
    { [StringLength(50)] public virtual String Name{ get;set;}
    public virtual Email Email{ get:set;}
    }

    public partial class Email

    {
    
        private String _Address;
    
        public Email()
        {
            _Address = String.Empty;
        }
    
        public Email( String emailAddress )
        {
            _Address = emailAddress;
        }
    
        public static implicit operator String( Email emailAddress )
        {
            return emailAddress.ToString();
        }
        public static implicit operator Email( String emailAddress )
        {
            return new Email( emailAddress );
        }
    }
    

    contact would map to
    contacts table with a varchar(50) Name column along with a varchar(255) email column.

  3. Support Staff 4 Posted by Paul Batum on 18 May, 2010 12:00 PM

    Paul Batum's Avatar

    Okay you have two major options I think.
    1. Make email a component.
    2. Make email an IUserType

    Google and the nhibernate documentation will tell you more about the two options.

    I would probably try a component first.
    http://wiki.fluentnhibernate.org/Fluent_mapping#Components

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is the opposite of down?