All of my objects and value objects implement the IEntity and IValueObject marker interfaces. I set them so that they are considered as components:
public override bool IsComponent(Type type) { return typeof(IValueObject).IsAssignableFrom(type); } public override bool ShouldMap(Type type) { return typeof(IEntity).IsAssignableFrom(type) || typeof(IValueObject).IsAssignableFrom(type); }
Unfortunately, this, apparently, does not allow entities that have collections of value objects to be automatically deleted as collections of components. For example:
public class MyEntity : IEntity { public IList<MyValueObject> Objects { get; set; } } public class MyValueObject : IValueObject { public string Name { get; set; } public string Value { get; set; } }
Is there a way to define a convention so that at any time when IEntity has an IList type that implements IValueObject , it displays as if I pointed out:
HasMany(x => x.Objects) .Component(x => { x.Map(m => m.Name); x.Map(m => m.Value); });
What I do not want to do is manually perform these overrides for each class and write out each property for the value object again and again.
nhibernate components fluent-nhibernate automapping value-objects
Joran
source share