可以有一个通过IUserType映射的实体集合吗?例如:
class Foo
{
public int Id { get; set; }
public ISet<Special> Items { get; set; }
}
class Special
{
public Special(string columnValue)
{
_val = columnValue;
}
public override string ToString()
{
return _val.TranformInInterestingWays();
}
private string _val;
}
class SpecialUserTypeForMapping : IUserType
{
// assume that all the right stuff is here
// for using the non-default constructor on the way in
// and calling ToString() on the way out
}如果我没看错文档,那么<set>、<one-to-many>、<many-to-many>和<class>元素都不支持用于将IUserType映射应用到<property>的"type“属性。
发布于 2009-09-04 18:59:15
最方便的解决方案似乎是使用<element>元素,如下所示:
<class name="Foo" table="foos">
<id name="Id" />
<set name="Items" table="foo_special">
<key column="fooId" />
<element column="special_value" type="SpecialUserTypeForMapping" />
</set>
</class>从数据库中检索不同的Foo实例没有问题,但不清楚是否可以针对special_value列编写查询,这在我的场景中是必需的。This question似乎表明事实并非如此。
https://stackoverflow.com/questions/1376278
复制相似问题