BjartN
BjartN

Reputation: 5487

Fluent-NHibernate mapping

In my database I have field containg a comma delimited list of emails. How would I map that to a IList<string> in my model ?

Upvotes: 0

Views: 573

Answers (2)

James Gregory
James Gregory

Reputation: 14223

You should implement an IUserCollection, which would map your CSV column to an actual list of emails, then serialize it back on save.

Upvotes: 2

Anton Gogolev
Anton Gogolev

Reputation: 115691

The table in question is not even First Normal Form, which is bad.

The only way you can possibly do that is something along these lines:

class Foo
{       
    private List<string> emails = new List<string>();       

    public string _Emails 
    { 
        get { return string.Join(",", emails.ToArray()); }
        set { emails = new List<string>(value.Split(',')); }
    }       

    public IList<string> Emails
    { 
        get { return emails; }          
    }
}

and map _Emails property.

Edit

One more solution is implemention your own IUserType or IUserCollection. Thus your model will be much prettier.

Upvotes: 0

Related Questions