コード例 #1
0
        public void Apply(Type entityType, @class classElement, IEnumerable<Type> entityTypes, hibernatemapping hbm)
        {
            //use reflection to get the Id property from the current class
            var idMember = entityType.GetFieldsAndProperties().SingleOrDefault(e => e.Name.ToLower() == "id" || e.GetCustomAttributes(typeof(KeyAttribute), false).Any());
            if (idMember != null)
            {

                var idType = idMember.ReturnType();
                //if the id property exists, add a new id element to the @class element
                classElement.id = new id()
                {
                    name = idMember.Name.Sanitise(),
                    column = { new column()
                        .Setup(idMember)
                        .Apply(c => c.notnull = true)
                        //.Apply(c => c.index = "PK_" + classElement.table) //doesn't work for PK!
                    }
                };

                if (CanUseHiloGenerator(idType)) //if is integer of some kind
                {
                    classElement.id.generator = new generator()
                    {
                        @class = "hilo",
                        param =
                            {
                                param.Parse(@"<param name=""max_lo"" xmlns=""urn:nhibernate-mapping-2.2"" >10</param>"),
                                param.Parse(@"<param name=""where"" xmlns=""urn:nhibernate-mapping-2.2"" >entity = '" + classElement.table + "'</param>"),
                                param.Parse(@"<param name=""table"" xmlns=""urn:nhibernate-mapping-2.2"" >HiloValues</param>"),

                            }
                    };
                    this.entities.Add(classElement.table);
                }
                else if (idType == typeof(Guid))
                {
                    classElement.id.generator = new generator() { @class = "guid.comb"} ;
                }

            }
        }
コード例 #2
0
 public XRootNamespace(@class root)
 {
     this.doc = new XDocument(root.Untyped);
     this.rootObject = root;
 }