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)
{
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="****">