//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Entity Developer tool using NHibernate Fluent Mapping template.
// Code is generated on: 21.06.2012 13:24:47
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using FluentNHibernate.Mapping;
using FluentNHibernate.MappingModel.Collections;

namespace ManyToMany
{
    public class ShopMap : ClassMap<Shop>
    {
        public ShopMap()
        {
              Table("Shops");
              LazyLoad();
              Id(x => x.ShopID)
                .Column("ShopID")
                .CustomType("Int32")
                .Access.Property()
                .CustomSqlType("INTEGER")
                .Not.Nullable()                
                .GeneratedBy.Identity();
              Component(x => x.ShopDescription,
                        aShopDescription => {
                        aShopDescription.Access.Property();
                        aShopDescription.Map(x => x.Name)    
                            .Column("ShopName")
                            .CustomType("String")
                            .Access.Property()
                            .Generated.Never()
                            .CustomSqlType("VARCHAR")
                            .Not.Nullable()
                            .Length(15);
                        aShopDescription.Map(x => x.Address)    
                            .Column("ShopAddress")
                            .CustomType("String")
                            .Access.Property()
                            .Generated.Never()
                            .CustomSqlType("VARCHAR")
                            .Length(60);
                        aShopDescription.HasManyToMany<Company>(x => x.Partners)    
                                    .Access.Property()
                                    .AsSet()
                                    .Cascade.None()
                                    .LazyLoad()
                                    // .OptimisticLock.Version() /*bug (or missing feature) in Fluent NHibernate*/
                                    .Generic()
                                    .Table("CompanyShops")
                                    .FetchType.Join()
                                    .ChildKeyColumns.Add("CompanyID", mapping => mapping.Name("CompanyID")
                                                                                         .SqlType("INTEGER")
                                                                                         .Not.Nullable())
                                    .ParentKeyColumns.Add("ShopID", mapping => mapping.Name("ShopID")
                                                                                         .SqlType("INTEGER")
                                                                                         .Not.Nullable());
                        });
        }
    }

    public class FactoryMap : ClassMap<Factory>
    {
        public FactoryMap()
        {
              Table("Factories");
              LazyLoad();
              Id(x => x.FactoryID)
                .Column("FactoryID")
                .CustomType("Int32")
                .Access.Property()
                .CustomSqlType("INTEGER")
                .Not.Nullable()                
                .GeneratedBy.Identity();
              Component(x => x.FactoryDescription,
                        aFactoryDescription => {
                        aFactoryDescription.Access.Property();
                        aFactoryDescription.Map(x => x.Name)    
                            .Column("FactoryName")
                            .CustomType("String")
                            .Access.Property()
                            .Generated.Never()
                            .CustomSqlType("VARCHAR")
                            .Not.Nullable()
                            .Length(15);
                        aFactoryDescription.Map(x => x.Address)    
                            .Column("FactoryAddress")
                            .CustomType("String")
                            .Access.Property()
                            .Generated.Never()
                            .CustomSqlType("VARCHAR")
                            .Length(60);
                        aFactoryDescription.HasManyToMany<Company>(x => x.Partners)    
                                    .Access.Property()
                                    .AsSet()
                                    .Cascade.None()
                                    .LazyLoad()
                                    // .OptimisticLock.Version() /*bug (or missing feature) in Fluent NHibernate*/
                                    .Generic()
                                    .Table("CompanyFactories")
                                    .FetchType.Join()
                                    .ChildKeyColumns.Add("CompanyID", mapping => mapping.Name("CompanyID")
                                                                                         .SqlType("INTEGER")
                                                                                         .Not.Nullable())
                                    .ParentKeyColumns.Add("FactoryID", mapping => mapping.Name("FactoryID")
                                                                                         .SqlType("INTEGER")
                                                                                         .Not.Nullable());
                        });
              Map(x => x.WorkersCount)    
                .Column("WorkersCount")
                .CustomType("Int32")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("INTEGER");
        }
    }

    public class CompanyMap : ClassMap<Company>
    {
        public CompanyMap()
        {
              Table("Companies");
              LazyLoad();
              Id(x => x.CompanyID)
                .Column("CompanyID")
                .CustomType("Int32")
                .Access.Property()
                .CustomSqlType("INTEGER")
                .Not.Nullable()                
                .GeneratedBy.Identity();
              Map(x => x.CompanyName)    
                .Column("CompanyName")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("VARCHAR")
                .Not.Nullable()
                .Length(15);
        }
    }

}
