views:

451

answers:

2

Hi all,

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

            });
        }
+1  A: 

I would create a map for Country and use m.References(x => x.Country).

Daniel A. White
But then wouldn't that be treating country as an Entity rather than a value object? Maybe there's no downside with doing that though.
UpTheCreek
+4  A: 

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
    }
UpTheCreek
Amazing. I did not realize you could nest them like this. I have been working on doing this for a week.
Nathan Lee