I have an IUserType which maps two columns into a single type like this:
....
public object NullSafeGet(IDataReader rs, string[] names, object owner)
{
return new FooBar(rs[names[0]], rs[names[1]]);
}
....
I'm having trouble specifying the two column names using Fluent NHibernate. I've tried this:
Map(x => x.Boz).Columns.Add("GLUB","SHERP").CustomType<FooBarUserType>();
But the second column name is ignored. How can I specify the two column names using Fluent NHibernate?
Try ICompositeUserType. This can handle multiple columns. But sometimes colleagues forget about Component mapping which is often usable and much more simple to map:
Use
and create a ComponentMap mapping class like:
This will create 2 columns in your original table (does not create a own table for FooBar-entities): FooBarProp1 and FooBarProp2.
The alternative with ICompositeUserType sucks with my fluent version: I always get error messages "Wrong number of columns" and the hints like Columns.Clear() wont work.
Regards, Michael