Michael...
Please have a look to the events implemented for the ConvetionalModelMapper
and, if you don't want use it, please add the same implementation to the
ModelMapper events.
I would avoid to see mappings with all those accessor setting.
BeforeMapProperty += MemberReadOnlyAccessor;
BeforeMapComponent += MemberReadOnlyAccessor;
BeforeMapBag += MemberReadOnlyAccessor;
BeforeMapSet += MemberReadOnlyAccessor;
BeforeMapMap += MemberReadOnlyAccessor;
BeforeMapList += MemberReadOnlyAccessor;
BeforeMapManyToOne += MemberReadOnlyAccessor;
BeforeMapOneToOne += MemberReadOnlyAccessor;
BeforeMapAny += MemberReadOnlyAccessor;
protected virtual void MemberReadOnlyAccessor(IModelInspector
modelInspector, PropertyPath member, IAccessorPropertyMapper
propertyCustomizer)
{
if (MatchReadOnlyProperty(member.LocalMember))
{
propertyCustomizer.Access(Accessor.ReadOnly);
}
}
protected bool MatchReadOnlyProperty(MemberInfo subject)
{
var property = subject as PropertyInfo;
if (property == null)
{
return false;
}
if (CanReadCantWriteInsideType(property) ||
CanReadCantWriteInBaseType(property))
{
return PropertyToField.GetBackFieldInfo(property) == null;
}
return false;
}
Thanks.
On Thu, Apr 28, 2011 at 12:01 PM, Michael DELVA <[email protected]>wrote:
> Hello all,
>
> I have this interface:
>
> public interface IBaseEntity : IEquatable<BaseEntity>
> {
> int Id { get; set; }
> bool IsTransient { get; }
> }
>
> public interface IStatistic : IBaseEntity
> {
> string Name { get; }
> bool Attack { get; }
> int Value { get; }
> }
>
> implemented by this abstract class:
>
> public abstract class Statistic : BaseEntity, IStatistic
> {
> public abstract string Name { get; }
> public abstract bool Attack { get; }
> public abstract int Value { get; }
> }
>
> This abstract class in derived in this class:
>
> public class MyStat : Statistic
> {
> public override string Name
> {
> get { return "Hello"; }
> }
>
> public override bool Attack
> {
> get { return false; }
> }
>
> public override int Value
> {
> get { return 100; }
> }
> }
>
> Using this mappings:
>
> mapper.Class<Statistic>(cm =>
> {
> cm.Id(a => a.Id, idm =>
> {
> idm.Access(Accessor.Property);
> idm.Generator(Generators.Native);
> });
>
> cm.Property(s => s.Name, pm => pm.Access(Accessor.ReadOnly));
> cm.Property(s => s.Attack, pm => pm.Access(Accessor.ReadOnly));
> cm.Property(s => s.Value, pm => pm.Access(Accessor.ReadOnly));
> });
>
> mapper.Class<Action>(cm =>
> {
> cm.Id(a => a.Id, idm =>
> {
> idm.Access(Accessor.Property);
> idm.Generator(Generators.Native);
> });
>
> cm.ManyToOne(a => a.Statistic, pm =>
> {
> pm.NotNullable(false);
> pm.Column("StatisticId");
> });
> });
>
> and this code:
>
> [Fact]
> public void Test()
> {
> using (ISession session = SessionFactory.OpenSession())
> {
> session.Save(new MyStat());
> session.Flush();
> }
> }
>
> I have this error:
>
>
> NHibernate.MappingException: No persister for:
> Emidee.CommonEntities.Tests.NHibernate.StatisticsInNHibernateTests+MyStat
>
> How should I change my mappings to make this work?
>
> Thanks in advance
>
> Michael
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
--
Fabio Maulo
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.