使用 Fluent NHibernate 映射集合类型

发布于 2024-09-09 03:32:48 字数 1036 浏览 1 评论 0原文

我在我的项目中使用了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨的味道风的声音 2024-09-16 03:32:48

试试这个:

HasMany(x => x.Services)
    .KeyColumn("Vendor_Id")
    .AsBag()
    .Cascade.All()
    .Not.LazyLoad();

这对我来说非常有用!

Try this :

HasMany(x => x.Services)
    .KeyColumn("Vendor_Id")
    .AsBag()
    .Cascade.All()
    .Not.LazyLoad();

It works great for me!

后知后觉 2024-09-16 03:32:48

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文