(Fluent). NHibernate mapping: use IUserType to map custom foo class - if boo.foo.Id is 0 then write to DB: boo.foo = NULL
I have the following construction:
class Person {
int Id;
Foo fooObject;
}
class Foo {
int Id;
//some more properties - doesn't matter
}
The database for this example is pretty simple;
Person table (int Id, int foo_Id)
Foo table (int Id, some more properties ...)
I often end up with a Person object that contains an initialized Foo object that has no value (for example, Id is 0). In this case, I want to store NULL in the Person.foo_Id database field.
I guess I should be using IUserType for such a conversion, but I just don't know how I should implement this with a custom Foo class ... Anyone have any experience with this topic? By the way, I am using FluentNHibernate.
Thanks in advance!
+2
source to share