Generate Database from NHibernate config files

后端 未结 3 1502
轻奢々
轻奢々 2020-12-29 14:13

Is it possible to generate the database tables and c# classes from NHibernate config files? Afterwards, is it possible to change the config files and update the tables and

3条回答
  •  有刺的猬
    2020-12-29 14:54

    Yes it is possible to generate the database tables and C# classes from the NHibernate config files. Let me explain with this example here .

    1 : Address.hbm.xml

    
    
    
    
        
    
            
                
                            
            
    
    
    
            
                
            
    
            
                
            
    
            
                
            
    
            
                
            
    
            
                
            
    
    
    
    
        
    
    

    Step 2 : Just by the looking at the configuration file , you Address object siply looks like the following

    using System;
    
    namespace Your.Domain
    {
    
        public partial class Address
        {
    
    
    
            #region Attributes and Associations
    
            private string _address1;
            private string _address2;
            private string _city;
            private long _id;
            private string _state;
            private string _zipcode;
    
            #endregion
    
            #region Properties
    
            /// 
            /// 
            /// 
            public virtual string Address1
            {
                get { return _address1; }
                set { this._address1 = value; }
            }
    
            /// 
            /// 
            /// 
            public virtual string Address2
            {
                get { return _address2; }
                set { this._address2 = value; }
            }
    
            /// 
            /// 
            /// 
            public virtual string City
            {
                get { return _city; }
                set { this._city = value; }
            }
    
            /// 
            /// 
            /// 
            public virtual long Id
            {
                get { return _id; }
                set { this._id = value; }
            }
    
            /// 
            /// 
            /// 
            public virtual string State
            {
                get { return _state; }
                set { this._state = value; }
            }
    
            /// 
            /// 
            /// 
            public virtual string Zipcode
            {
                get { return _zipcode; }
                set { this._zipcode = value; }
            }
    
    
            #endregion 
        }
    }
    

    Step 3 : And again if you look at the "Column" name property and its data type that is actually refers to the Actual backend database table called "Address".

    There are also huge amount of tools that help you to generate all these artifacts for you based on different input such as UML, Or Actual Database schema etc.

提交回复
热议问题