Esempio n. 1
0
        static void mapper_BeforeMapManyToOne(
            NHibernate.Mapping.ByCode.IModelInspector modelInspector,
            NHibernate.Mapping.ByCode.PropertyPath member,
            NHibernate.Mapping.ByCode.IManyToOneMapper propertyCustomizer)
        {
            /*
             *
             *  public class Product
             *  {
             *      protected internal  int                             ProductId       { get; set; }
             *
             *      public              TheProduction.ProductCategory   ProductCategory { get; protected internal set; }
             *      public              string                          ProductName     { get; protected internal set; }
             *  }
             *
             */

            // ProductCategory property name maps to ProductCategoryId column name
            propertyCustomizer.Column(member.ToColumnName() + "Id");
        }
Esempio n. 2
0
        static void Mapper_BeforeMapManyToOne(
            NHibernate.Mapping.ByCode.IModelInspector modelInspector,
            NHibernate.Mapping.ByCode.PropertyPath propertyPath,
            NHibernate.Mapping.ByCode.IManyToOneMapper manyToOneMapper
            )
        {
            /*
             *
             *  public class Product
             *  {
             *      protected internal  int                             ProductId       { get; set; }
             *
             *      public              TheProduction.ProductCategory   ProductCategory { get; protected internal set; }
             *      public              string                          ProductName     { get; protected internal set; }
             *  }
             *
             */

            // ProductCategory property name maps to product_category_fk column name

            string columnName = propertyPath.ToColumnName();

            string postgresFriendlyName = columnName.ToLowercaseNamingConvention();



            if (!(columnName == "CreatedBy" || columnName == "ModifiedBy"))
            {
                postgresFriendlyName = postgresFriendlyName + "_fk";
            }


            manyToOneMapper.Column(postgresFriendlyName);
            // Looks like we need to use no-proxy, we might encounter ghost object
            // https://ayende.com/blog/4378/nhibernate-new-feature-no-proxy-associations
            manyToOneMapper.Lazy(NHibernate.Mapping.ByCode.LazyRelation.Proxy);
        }