1

When mapping my Property with Fluent NHibernate, on insert, I would like to use the database default value only when my Property is null. So for instance, if the db default is 100, and my property is null, it should insert 100, otherwise insert the value of my property ( say 25 ).

Thanks.

1 Answer 1

5

You can do it by mapping override:

public class MyEntityMappingOverride : IAutoMappingOverride<MyEntity>
{
     public void Override(AutoMapping<MyEntity> mapping)
     {
         mapping.Map(x => x.MyProperty).Default("100");
     }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.