使用 Fluent NHibernate 映射集合类型
我在我的项目中使用了 Fluent NH,但在使用 Collection 类时遇到了一些问题。这是我的类的代码,
public class Vendor
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Services Services { get; set; }
}
public class Services : IList<Service>
{
}
public class Service
{
int id{ get; set; }
int Code { get; set; }
}
而不是将服务作为供应商类中的列表,
public virtual IList<Service> Services { get; set; }
我想使用服务集合类。
和映射代码
public class VendorMap : ClassMap<Vendor>
{
public VendorMap()
{
Table("Vendor");
Id(x => x.Id);
Map(x => x.Name);
HasMany<Service>(x => x.Services)
.KeyColumn("Vendor_Id")
.CollectionType<Services>()
.Not.LazyLoad();
}
我收到此错误“自定义类型未实现 UserCollectionType:服务”
有关如何映射此错误的任何想法吗?
提前致谢。
I've used Fluent NH in my project but I'm having some problems with using the Collection class. Here's the code for my classes
public class Vendor
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Services Services { get; set; }
}
public class Services : IList<Service>
{
}
public class Service
{
int id{ get; set; }
int Code { get; set; }
}
this instead of put service as list in the vendor class
public virtual IList<Service> Services { get; set; }
I want to use services collection class.
and the mapping code
public class VendorMap : ClassMap<Vendor>
{
public VendorMap()
{
Table("Vendor");
Id(x => x.Id);
Map(x => x.Name);
HasMany<Service>(x => x.Services)
.KeyColumn("Vendor_Id")
.CollectionType<Services>()
.Not.LazyLoad();
}
I got this error "Custom type does not implement UserCollectionType: Services"
Any ideas on how to map this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
这对我来说非常有用!
Try this :
It works great for me!
NHibernate 不允许映射这种类型的集合类。它们必须是一个接口,例如
IList
,因为 NHibernate 提供了它自己的实现。这个实现显然不符合Services类的接口,因此NHibernate无法映射它。
NHibernate does not permit mapping collection classes of this type. They must be an interface, like
IList<T>
, as NHibernate provides it's own implementation.This implementation obviously does not meet the interface of the
Services
class, so NHibernate is unable to map it.