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

I am creating a model binder for 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) { 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 an entity key value is unsaved in NHibernate? that is, what would replace **** IsUnsavedValue(value) **** with?

Or is there a way to get the value of the unsaved id value in the mapping file. those. **** as follows:

 <id unsaved-value="****"> 
+4
source share
1 answer

try mapping.Identifier.NullValue

+2
source

Source: https://habr.com/ru/post/1301958/


All Articles