문제

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

   Component(x=>x.Boz) //instead of Map(x=>x.Boz)

and create a ComponentMap mapping class like:

   public class FooBarMap: ComponentMap<FooBar>
       {
           public FooBarMap()
           {
               Map(x => x.FoobarProp1);
               Map(x => x.FoobarProp2);
           }
       }

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

I had the same issue in a project I was working on.

I was able to get it to work using the following:

Map(x => x.Boz).Columns.Add("GLUB").Columns.Add("SHERP").CustomType<FooBarUserType>();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top