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 ?
views:
275answers:
2
A:
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.
Anton Gogolev
2009-02-09 09:49:37
Well, sometimes you are not responsible for designing the database.Your solution will work with some tweaking (the client must be able to add addresses to the Emails field as well), but I was hoping for some kind of user defined mapping. Im not very keen on polluting my model :)
BjartN
2009-02-09 10:16:36
+2
A:
You should implement an IUserCollection
, which would map your CSV column to an actual list of emails, then serialize it back on save.
James Gregory
2009-02-09 11:18:04