简体   繁体   English

NHibernate版本属性不起作用

[英]NHibernate version property is not working

Using Sharp Architecture / Fluent NHibernate, I set-up a Version property (with an int ) for my class, however, even though updating its objects correctly updates the Version number, no error is thrown and the versions are basically merged instead of throwing an exception. 使用Sharp Architecture / Fluent NHibernate,我为我的类设置了Version属性(带有int ),即使更新其对象正确地更新了Version编号,也不会引发错误,并且基本上合并了版本,而不是抛出例外。

public class MyClassMap : IAutoMappingOverride<MyClass>
{
    public void Override(AutoMapping<MyClass> mapping)
    {
        mapping.Version(x => x.Version);
        mapping.OptimisticLock.Version();
    }
}

Notice the version is different between two concurrent commits, yet nothing happens. 注意两次并发提交的版本不同,但是什么也没有发生。

What gives? 是什么赋予了?

Edit: Here's the code: 编辑:这是代码:

    public ActionConfirmation SaveOrUpdate(IncidenciaDetalleModel model)
    {
        Incidencia incidencia = model.Codigo == null
                                    ? new Incidencia(Convert.ToInt32(model.Solicitante.Id))
                                    : Load(model.Guid);

        TransferFormValuesTo(incidencia, model);

        // Invoke Sharp NHibernate's SaveOrUpdate()
        Incidencia saved = base.SaveOrUpdate(incidencia);

        return ActionConfirmation.CreateSuccessConfirmation(saved);
    }



    private void TransferFormValuesTo(Incidencia incidencia, IncidenciaDetalleModel model)
    {
        incidencia.Resumen = model.Resumen.Trim();
        incidencia.Descripcion = model.Descripcion.Trim();
        incidencia.Solicitante = model.Solicitante.Id.ToString(CultureInfo.InvariantCulture);
        incidencia.Regional = regionalTask.Load(model.Regional.GetRegionalId());
    }

you said the Version updates fine so not applying Conventions fall out. 您说版本可以很好地更新,所以不应用约定会失效。

i guess there is no real concurrent update. 我猜没有真正的并发更新。 you use Load(model.Guid) which doesnt load the object from database but creates a proxy for it. 您使用Load(model.Guid)不会从数据库中加载对象,但会为其创建代理。 it is loaded in TransferFormValuesTo updated and immediatly saved. 它已加载到TransferFormValuesTo更新并立即保存。 Only between TransferFormValuesTo and SaveOrUpdate() there can be a race condition leading to stale objects. 仅在TransferFormValuesToSaveOrUpdate()之间, SaveOrUpdate()存在导致过期对象的竞争条件。

you could enable logging for "NHibernate.SQL" to see if the Update of client 1 really is after the the SELECT of client 2 您可以启用“ NHibernate.SQL”的日志记录,以查看客户端1的更新是否确实在客户端2的SELECT之后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM