开发者

How to check if the key is an unsaved value in NHibernate

I am creating a model binder to use with asp.net mvc. This is what I got so far:

public class ModelBinder : DefaultModelBinder
{
    protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
    {
        PersistentClass mapping = DataAccess.Configuration.GetClassMapping(modelType);
        if(mapping != null)
        {
       开发者_Python百科     ValueProviderResult value = bindingContext.ValueProvider.GetValue(mapping.IdentifierProperty.Name);
            if(value != null)
            {
                object keyValue = value.ConvertTo(mapping.Key.Type.ReturnedClass);
                if(mapping.Key.**** IsUnsavedValue(value) ****)
                {
                    return DataAccess.Session.Load(modelType, keyValue);
                }
            }
        }
        return base.CreateModel(controllerContext, bindingContext, modelType);
    }
}

Is there a way to check if the value of an entity key is unsaved in NHibernate? i.e. What would I replace the **** IsUnsavedValue(value) **** with?

Or is there a way to get the value of the unsaved-value of the id in the mapping file. i.e. The **** in the following:

<id unsaved-value="****">


try the mapping.Identifier.NullValue

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜