views:

209

answers:

1

Hello. I'm having some trouble to create a mapping.

Let's say that persons read books:

class Person : Entity
{
    public virtual string Name { get; set; }
    public virtual IList<Book> Books { get; set; }
    /* ... */
}

class Book : ValueObject
{
    public virtual string Name { get; private set; }
    public virtual int Pages { get; private set; }

    public Book(string name, int pages)
    {
        Name = name;
        Pages = pages;
    }

    public override string ToString()
    {
        return Name + "-" + Pages;
    }
}

I must create a mapping (with Fluent NHibernate) that will map this onto a Persons table, something like:

Person:
  Id: int, PK
  Name: string
  Books: string

The Books column will be a "serialized" representation of the IList Books collection. A row should look something like:

Person:
  Id = 1
  Name = "Bruno"
  Books = "Code Complete-960,The Hobbit-310"

In the domain I'm modelling, I have an entity with many such lists, and I would like to store each of the lists in a column, just like the Books column above.

I've found (here in SO) some questions dealing with how to map IList to a single column, pointing to a StringListObjectType : IUserType implementation that solves the problems. But this is not a solution to my problem.

How can I proceed?

Thanks!

A: 

I've been dealing with the same problem, and it looks like the IUserType actually solves the problem.

Check out my question (+ answer):
http://stackoverflow.com/questions/2754138/fluent-nhibernate-mapping-listpoint-as-value-to-single-column

Paja