Mapping component throws AmbigousComponentReferenceException
I Have a component defined as follow:
public class Tracking
{
public virtual string CreatedBy { get; set; }
public virtual DateTime CreatedOn { get; set; }
public virtual string UpdatedBy { get; set; }
public virtual DateTime UpdatedOn { get; set; }
public virtual string DeletedBy { get; set; }
public virtual DateTime DeletedOn { get; set; }
public Tracking()
{
CreatedBy = Environment.UserName;
UpdatedBy = Environment.UserName;
}
}
Which is mapped using the following mapping:
class TrackingMap : ComponentMap<Tracking>
{
public TrackingMap()
{
Map(c => c.CreatedBy);
Map(c => c.CreatedOn);
Map(c => c.UpdatedBy);
Map(c => c.UpdatedOn);
Map(c => c.DeletedBy);
Map(c => c.DeletedOn);
}
}
Then, I have another class that references the component:
public class Mission
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Tracking Tracking { get; set; }
}
With the corresponding mapping:
class MissionMap : ClassMap<Mission>
{
public MissionMap()
{
Id(x => x.Id);
Map(x => x.Name);
Component(x => x.Tracking);
}
}
My problem When I build the session factory, I have a
FluentConfigurationException with the message
Multiple external components for 'Tracking', referenced from property
'Tracking' of 'Mission', unable to continue.
However, when I use inline mapping:
class MissionMap : ClassMap<Mission>
{
public MissionMap()
{
Id(x => x.Id);
Map(x => x.Name);
Component(x => x.Tracking, m =>
{
m.Map(c => c.CreatedBy);
m.Map(c => c.CreatedOn);
m.Map(c => c.UpdatedBy);
m.Map(c => c.UpdatedOn);
m.Map(c => c.DeletedBy);
m.Map(c => c.DeletedOn);
});
}
}
It works just well.
Any help will be greatly appreciated.
No comments:
Post a Comment