开发者

Implementing IPropertyAccessor NHibernate

During usage of NHibernate ...

One strange prob开发者_运维技巧lem that I have bumped into was multiple updates after Session.Flush() command. No data actually changed ... Just wanted to perform Select that all, in my case there was 1000 updates – one per returned row!!!

Such behavior happens only if I’m using properties with custom PropertyAccessor as access type. The reason that I have created custom property was that I have uint and ushort types in my objects so I wanted to cast them from (long or Int32 correspondingly )on the Setter.

The question is how can I disable those updates or why my custom Setter causing such behavior?

void Set(object target, object value)
        {
            If(Value.GetType() == typeof(long))
            {
            Target.GetType().GetProperty(_propertyName).SetValue((uint)value);
            }
        }

Thanks in advance,

Update:------ How can i disable this dirty check before every Flush?


It seems like your PropertyAccessor is messing up the NHibernate Session dirty tracking. This post shows how you can test if an entity is dirty. You should add this code and debug into the NHibernate source to see exactly why your entities are considered dirty. I suspect that the types won't match.

Update:

Another approach would be to keep your Entity definitions as unsigned but change the db mappings to use signed types in the database. This is how using Fluent NHIbernate and SQL server:

public class TestEntity : Entity
{
    public virtual uint Unsigned { get; set; }
    public virtual ushort UnsignedShort { get; set; }
}

public class TestEntityMap : ClassMap<TestEntity>
{
    public TestEntityMap()
    {
        Map( x => x.Unsigned ).CustomSqlType( "bigint" );
        Map( x => x.UnsignedShort ).CustomSqlType( "int" );
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜