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="****">
Geoff source share