Question

I have entity object User and value object Profile.

public class User : Entity<Guid>
{
    ...
    public virtual Profile Profile { get; set; }
}

public class Profile
{
    ...
    public virtual User User { get; set; }
}

I'm using nhibernate mapping by code and I'm mapping Profile value object in UserMap.cs as component like Component(c => c.Profile, ProfileMap.Mapping());

ProfileMap.cs

public class ProfileMap
{
    public static Action<IComponentMapper<Profile>> Mapping()
    {
        return c =>
        {
           ...
           c.Property(p => p.User);               
        }
    }
}

On unit mapping tests I'm getting error with inner exception message

"Could not determine type for: MyApp.Domain.Model.User, MyApp.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(User)"}

p.s. when I comment out mapping User property from ProfileMap and leaving Profile property in UserMap mapping works.

Was it helpful?

Solution

User is most probably not a Property, but a relation type (many-to-many, or many-to-one or something). Most probably it is the components parent.

public static Action<IComponentMapper<Profile>> Mapping()
{
    return c =>
    {
       ...
       c.Parent(p => p.User);               
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top