Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping nested components in Fluent NHibernate

I have a 'User' Entity that contains an 'Address' Value Object. I have this mapping ok using FNH's Component concept. However, the Address VO also contains a Country which is another value object. I had assumed that this should be just nested as another component, but this doesn't seem to work. Can anyone tell me how I should solve this?

Code for mapping is below...

Thanks!

public UserMapping()
        {
            Table("Users");
            Id(c => c.Id).GeneratedBy.HiLo("100");
            Map(c => c.UserName).Not.Nullable().Length(64);
            Map(c => c.Email).Not.Nullable().Length(128);
            Map(c => c.Password).Not.Nullable().Length(256);
            Map(c => c.Roles).Length(64);
            Map(c => c.FirstName).Not.Nullable().Length(64);
            Map(c => c.LastName).Not.Nullable().Length(64);
            Map(c => c.BirthDate).Not.Nullable();
            //Address
            Component(x => x.Address, m =>
            {
                m.Map(x => x.AddressLine1).Not.Nullable();
                m.Map(x => x.AddressLine2);
                m.Map(x => x.City).Not.Nullable();
                m.Map(x => x.Region);
                m.Map(x => x.PostalCode).Not.Nullable();
                //*****Country Here********
                // country has Name and Code

            });
        }
like image 634
UpTheCreek Avatar asked Oct 01 '09 14:10

UpTheCreek


1 Answers

Ah, Jimmy Bogard from the FNH mailing list showed me - it's quite straightforward. I don't know what I was doing before! Anyway, for anyone else who's interested:

Component(c => c.Address, m =>
{
    m.Component(cp => cp.Country, m2 =>
    {
        m2.Map(x => x.Name); //etc
    } 
like image 118
UpTheCreek Avatar answered Sep 23 '22 04:09

UpTheCreek