views:

33

answers:

1

Hello guys.

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.

A: 

Try this :

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

It works great for me!

gillyb