C# FluentNHibernate例外情况:“;属性映射的列数错误";关于复合用户类型

C# FluentNHibernate例外情况:“;属性映射的列数错误";关于复合用户类型,c#,nhibernate,orm,fluent-nhibernate,C#,Nhibernate,Orm,Fluent Nhibernate,我试图将域模型中的一组实体映射到数据库中以逗号分隔的ID字符串。我已经编写了一个复合用户类型来处理这个问题: public class CustomerSetToCommaString : ICompositeUserType { public object GetPropertyValue(object component, int property) { throw new NotImplementedException(); }

我试图将域模型中的一组实体映射到数据库中以逗号分隔的ID字符串。我已经编写了一个复合用户类型来处理这个问题:

       public class CustomerSetToCommaString : ICompositeUserType
{
    public object GetPropertyValue(object component, int property)
    {
        throw new NotImplementedException();
    }

    public void SetPropertyValue(object component, int property, object value)
    {
        throw new NotImplementedException();
    }

    public bool Equals(object x, object y)
    {
        var set1 = x as ISet<Customer>;
        var set2 = x as ISet<Customer>;

        return (x == null) ? y == null : set1.SetEquals(set2);
    }

    public int GetHashCode(object x)
    {
        var set = x as ISet<Customer>;
        unchecked
        {
            return set == null ? 0 : set.Sum(relatie => relatie.GetHashCode());
        }
    }

    public object NullSafeGet(DbDataReader dr, string[] names, ISessionImplementor session, object owner)
    {
        var str = (string)NHibernateUtil.String.Get(dr, names[0], session);
        IList<int> ids = str.Split(',').Select(id => int.Parse(id.Trim())).ToList();
        return ((ISession) session).QueryOver<Customer>().WhereRestrictionOn(customer => customer.Id).IsInG(ids).List()
            .ToHashSet();
    }

    public void NullSafeSet(DbCommand cmd, object value, int index, bool[] settable, ISessionImplementor session)
    {
        var set = value as ISet<Customer>;
        NHibernateUtil.String.Set(cmd, string.Join(", ", set.Select(customer => customer.Id.ToString()).ToArray()), index, session);
    }

    public object DeepCopy(object value)
    {
        return ((ISet<Customer>) value).ToHashSet();
    }

    public object Disassemble(object value, ISessionImplementor session)
    {
        return DeepCopy(value);
    }

    public object Assemble(object cached, ISessionImplementor session, object owner)
    {
        return DeepCopy(cached);
    }

    public object Replace(object original, object target, ISessionImplementor session, object owner)
    {
        return original;
    }

    public string[] PropertyNames => new string[0];
    public IType[] PropertyTypes  => new IType[0];
    public Type ReturnedClass => typeof(ISet<Customer>);
    public bool IsMutable => true;
}
公共类CustomerSettoCommasString:ICompositeUserType
{
公共对象GetPropertyValue(对象组件,int属性)
{
抛出新的NotImplementedException();
}
public void SetPropertyValue(对象组件、int属性、对象值)
{
抛出新的NotImplementedException();
}
公共布尔等于(对象x、对象y)
{
var set1=x作为ISet;
var set2=x作为ISet;
返回(x==null)?y==null:set1.SetEquals(set2);
}
公共int GetHashCode(对象x)
{
var set=x作为ISet;
未经检查
{
返回set==null?0:set.Sum(relatie=>relatie.GetHashCode());
}
}
公共对象NullSafeGet(DbDataReader dr、字符串[]名称、ISessionImplementor会话、对象所有者)
{
var str=(string)NHibernateUtil.string.Get(dr,names[0],session);
IList id=str.Split(',).Select(id=>int.Parse(id.Trim()).ToList();
return((ISession)session.QueryOver().WhereRestrictionOn(customer=>customer.Id).IsInG(Id).List()
.ToHashSet();
}
public void NullSafeSet(DbCommand cmd、对象值、int索引、bool[]可设置、ISessionImplementor会话)
{
var set=作为ISet的值;
NHibernateUtil.String.Set(cmd,String.Join(“,”,Set.Select(customer=>customer.Id.ToString()).ToArray()),索引,会话);
}
公共对象深度复制(对象值)
{
返回((ISet)值).ToHashSet();
}
公共对象反汇编(对象值,ISessionImplementor会话)
{
返回DeepCopy(值);
}
公共对象组装(对象缓存、ISessionImplementor会话、对象所有者)
{
返回DeepCopy(缓存);
}
公共对象替换(对象原始、对象目标、ISessionImplementor会话、对象所有者)
{
归还原件;
}
公共字符串[]PropertyNames=>新字符串[0];
公共IType[]属性类型=>新IType[0];
公共类型ReturnedClass=>typeof(ISet);
public bool IsMutable=>true;
}
但是,当尝试使用
Map(x=>x.Customers).CustomType.Column(“客户”)我得到一个异常,属性映射的列数错误。它不应该尝试映射到单个列吗?我遗漏了什么吗?

经过一天令人沮丧的调试和谷歌搜索,我找到了答案。问题在于这一行:

public IType[] PropertyTypes  => new IType[0];
这将指定需要填写的列。当我把它改成:

public IType[] PropertyTypes  => new IType[1]{NHibernateUtil.String};
我指定列是单个字符串,这就解决了问题