1

I have following entities Country, State, City

I have also User entity.

Country, State and the City does not have relationship with user entity. User does not have direct relationship with Country, State or City.

I want to be able to update user address details in a way that user will select country, state and city and save this values. I'm thinking to introduce Address value object which will store this user address information.

Is this good idea? How would you handle this scenario?

I'm using nhibernate orm and mapping using Conformist (mapping by code approach) So I was thinking to map Address as value object

Component(c => c.Address, AddressMap.Mapping()); public class AddressMap { public static Action<IComponentMapper<Address>> Mapping() { return c => { c.Property(p => p.Country); c.Property(p => p.State); c.Property(p => p.City); }; } } 

having this in UserMap

Component(c => c.Address, AddressMap.Mapping()); 

I'm getting following error

The type initializer for 'NHibernate.SessionProvider' threw an exception. {"Could not determine type for: Model.Country, ..., for columns: NHibernate.Mapping.Column(Country)"}

Without this line Component(c => c.Address, AddressMap.Mapping()); in UserMap I do not have any error (also I do not have Address value object mapped :).

1 Answer 1

2

I would say, that issue here comes from the fact, that Country won't be value type (string including), but a reference. If that is the case, we cannot mapp it as c.Property() but as a reference:

c.ManyToOne(p => p.Country, "CountryId"); // reference c.Property(p => p.State); // value types represented c.Property(p => p.City); // by values in columns 

See this: Mapping-by-Code - ManyToOne for more details

ManyToOne(x => x.PropertyName, m => { m.Column("column_name"); // or... m.Column(c => { c.Name("column_name"); // other standard column options }); ... // many more 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.