Ok i found the documentation and tried to implement
IReferenceConvention. Is it what i need for many to one collections ?
Basically i want :
if my field is a mapped object and starts with id, make it a many to
one.
i found two ways to do it.
public class ManyToOneConventionCorrection
: IReferenceConvention
{
public bool Accept(IManyToOneInstance instance)
{
return instance.Name.ToLower().StartsWith("id");
}
public void Apply(IManyToOneInstance instance)
{
if (Accept(instance))
instance.Column = instance.Name;
}
}
void ApplyConventions(AutoPersistanceModel model)
{
model.Conventions.Setup(s =>s.Add<ManyToOneConventionCorrection>
())
}
It does not work, i never reach any of the code through debugger.
Works well for properties IPropertyConvention and class
IClassConvention, but not for IReference, at least not if reference is
a many to one.
i found this other way to define the convention which works well
2 .
void ApplyConventions(AutoPersistanceModel model)
{
var manyToOneConventionCorrection = ConventionBuilder.Reference.When(
x => x.Expect(y => y.Name.StartsWith("id")),
z => z.Column(z.Name));
autoPersistanceModel.Conventions.Setup(s =>s.Add
(manyToOneConventionCorrection))
}
On 17 août, 19:28, James Gregory <
jagregory....@gmail.com> wrote:
> By convention your property should be CarType, not IdCarType. If your column
> is IdCarType then you need to specify that manually by using Column, if this
> is a domain-wide convention then you should look into defining an actual
> convention <
http://wiki.fluentnhibernate.org/Conventions>.