Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 休眠拦截器_C#_Hibernate_Onload_Interceptor - Fatal编程技术网

C# 休眠拦截器

C# 休眠拦截器,c#,hibernate,onload,interceptor,C#,Hibernate,Onload,Interceptor,onload只带来实体的id,其他属性为null 我需要根据值验证实体是否采样​​具有IAccount的某些属性。以下是我目前的代码: public bool OnLoad(object entity, object id, System.Collections.IDictionary state) { IAccount account = (IAccount)entity; account.xxxxxx return true; } 如何执行此操作?O

onload只带来实体的id,其他属性为null

我需要根据值验证实体是否采样​​具有IAccount的某些属性。以下是我目前的代码:

public bool OnLoad(object entity, object id, System.Collections.IDictionary state)
{
    IAccount account = (IAccount)entity;
    account.xxxxxx        
    return true;
}

如何执行此操作?

OnLoad在实体对象实际初始化之前发生,因此“实体”将具有默认属性值,如您所见。您评估或更改实体状态的方式是通过传入的“状态”

您的示例并不是非常具体地描述您试图评估的内容,但是如果IAccount的IsSampling属性为false,让我们假设您希望执行一些日志记录:

public bool OnLoad(object entity, object id, System.Collections.IDictionary state)
{
    var isSampling = state["IsSampling"] as bool?;

    if( entity is IAccount && isSampling.HasValue )
    {
        if( !isSampling )
            Log.Write( string.Format( "Sampling for Account with id {0} is not active", id ) );
    }

    return false;
}
还要注意,我返回false,表示实体的状态没有被改变。如果要更改实体的状态,必须通过传入的状态集合(而不是通过传入的实体对象)进行更改,并且必须返回true


很难找到涵盖这一点的文档,但有一个来源(尽管有点过时):

OnLoad发生在实体对象实际初始化之前,因此“实体”将具有默认属性值,正如您已经看到的。您评估或更改实体状态的方式是通过传入的“状态”

您的示例并不是非常具体地描述您试图评估的内容,但是如果IAccount的IsSampling属性为false,让我们假设您希望执行一些日志记录:

public bool OnLoad(object entity, object id, System.Collections.IDictionary state)
{
    var isSampling = state["IsSampling"] as bool?;

    if( entity is IAccount && isSampling.HasValue )
    {
        if( !isSampling )
            Log.Write( string.Format( "Sampling for Account with id {0} is not active", id ) );
    }

    return false;
}
还要注意,我返回false,表示实体的状态没有被改变。如果要更改实体的状态,必须通过传入的状态集合(而不是通过传入的实体对象)进行更改,并且必须返回true

很难找到涵盖这一点的文档,但这里有一个来源(尽管有点过时):