Moon.ORM--配置說明


  1. 下載代碼生成器(庫也在代碼生成器的根目錄中)
     
    (順便說說MOON相對其他ORM的優勢: )
  2. 找到配置文件進行配置(實際項目中也一樣).
  3. 配置默認的系統數據庫類型(
                                各類數據庫的配置
    選擇一個你系統的數據庫配置(根據你的數據庫類型只選其一)

    1.MYSQL的配置 


    2.Sqlite的配置
                 3.PostgreSql的配置
     

    4.MSSQL的配置

     

     

  4. 給大家一個全配置,到時候好引用,記住只要其中一種類型
    <appSettings>
             <!--SQLITE-->
            
            <add key="dbType" value="SQLITE" />
            <add key="MYSQL_PATH" value="c:\MySql.Data.dll" /> <!--用mysql時設置-->
            <add key="OUT_PUT_PATH" value="D:\" /><!--代碼生成到此-->
            <add key="linkString" value="Data Source=Resource.s3db;Version=3;UseUTF16Encoding=True;" />

             <!--MSSQL-->----------------------------------------
             <add key="dbType" value="MSSQL" />
             <add key="linkString" value="Server=www.eee.com.cn;Database=hd01systemdb_new;uid=db;Password=mingyue1;" />
             <!--MYSQL-->---------------------------------------
             <add key="dbType" value="MYSQL" />
             <add key="MYSQL_PATH" value="c:\MySql.Data.dll" />
             <add key="linkString" value="Server=localhost;Database=MoonDB;Uid=root;Pwd=root;" />
             <!--PostgreSql-->---------------------------------
             <add key="dbType" value="PostgreSql" />
             <add key="linkString" value="Server=localhost;Database=MoonDB;User ID=postgres;Password=mingyue;" />
         </appSettings>
  5. 運行代碼生成器,以MYSQL為例.(注意此架構必須要有主鍵.且唯一的主鍵,非符合主鍵)      
  1. 給大家看看數據庫結構   
                  
  2.        
    項目配置文件   
           
            <add key="dbType" value="MYSQL" />
             <add key="MYSQL_PATH" value="c:\MySql.Data.dll" />
             <add key="linkString" value="Server=localhost;Database=MoonDB;Uid=root;Pwd=root;
    ;Charset=gb2312;
    "
     />
    用代碼生成器生成實體層. 加入你要做的項目中.(可以把這段代碼復制到項目中,也可以編譯引用)

     

    View Code
    using System;
    using Moon.Orm;
    using System.Collections.Generic;
    namespace MoonDB{
    public  class recordset:EntityBase{
         public recordset(): base(){
        SetEntityName( " `recordset` ");
        SetFieldsCount( 3);
        SetPrimaryField(recordsetTable.RecordID);
        SetIsSystemSetPrimaryKey( true);
        }
         private Int64  _RecordID;
         public Int64 RecordID{
         get{ return _RecordID;}
         set{
            _RecordID=value;
             if ( this.FieldsChangedDictionary.ContainsKey( " `RecordID` ")== false)
                { this.FieldsChangedDictionary.Add( " `RecordID` ",value);}        
    }
        }
         private Int64  _UserID;
         public Int64 UserID{
         get{ return _UserID;}
         set{
            _UserID=value;
             if ( this.FieldsChangedDictionary.ContainsKey( " `UserID` ")== false)
                { this.FieldsChangedDictionary.Add( " `UserID` ",value);}        
    }
        }
         private String  _Sumary;
         public String Sumary{
         get{ return _Sumary;}
         set{
            _Sumary=value;
             if ( this.FieldsChangedDictionary.ContainsKey( " `Sumary` ")== false)
                { this.FieldsChangedDictionary.Add( " `Sumary` ",value);}        
    }
        }
    }

    public  class recordsetTable{
         public  static  readonly Field RecordID= new Field( " `RecordID` ", true);
         public  static  readonly Field UserID= new Field( " `UserID` ", false);
         public  static  readonly Field Sumary= new Field( " `Sumary` ", false);
         static recordsetTable(){
            RecordID.TableName= " `recordset` ";
            UserID.TableName= " `recordset` ";
            Sumary.TableName= " `recordset` ";
        }
    }

    public  class userset:EntityBase{
         public userset(): base(){
        SetEntityName( " `userset` ");
        SetFieldsCount( 4);
        SetPrimaryField(usersetTable.ID);
        SetIsSystemSetPrimaryKey( true);
        }
         private String  _UserName;
         public String UserName{
         get{ return _UserName;}
         set{
            _UserName=value;
             if ( this.FieldsChangedDictionary.ContainsKey( " `UserName` ")== false)
                { this.FieldsChangedDictionary.Add( " `UserName` ",value);}        
    }
        }
         private Int32  _Age;
         public Int32 Age{
         get{ return _Age;}
         set{
            _Age=value;
             if ( this.FieldsChangedDictionary.ContainsKey( " `Age` ")== false)
                { this.FieldsChangedDictionary.Add( " `Age` ",value);}        
    }
        }
         private Int64  _ID;
         public Int64 ID{
         get{ return _ID;}
         set{
            _ID=value;
             if ( this.FieldsChangedDictionary.ContainsKey( " `ID` ")== false)
                { this.FieldsChangedDictionary.Add( " `ID` ",value);}        
    }
        }
         private String  _Address;
         public String Address{
         get{ return _Address;}
         set{
            _Address=value;
             if ( this.FieldsChangedDictionary.ContainsKey( " `Address` ")== false)
                { this.FieldsChangedDictionary.Add( " `Address` ",value);}        
    }
        }
    }

    public  class usersetTable{
         public  static  readonly Field UserName= new Field( " `UserName` ", false);
         public  static  readonly Field Age= new Field( " `Age` ", false);
         public  static  readonly Field ID= new Field( " `ID` ", true);
         public  static  readonly Field Address= new Field( " `Address` ", false);
         static usersetTable(){
            UserName.TableName= " `userset` ";
            Age.TableName= " `userset` ";
            ID.TableName= " `userset` ";
            Address.TableName= " `userset` ";
        }
    }

    }

     

    實際項目

     

     最后一步進行開發.

     

     

     
    using System;
    using System.Collections.Generic;
    using System.Data;
    using MoonDB;
    using Moon.Orm;
     
    namespace Test
    {
         class Program
        {
             public  static  void Main( string[] args)
            {
                userset user= new userset();
                user.Age= 12;
                user.UserName= " qsmy12345 "+DateTime.Now.Ticks;
                user.Address=user.UserName;
                 object newID=DBFactory.Add(user);
                Console.WriteLine();
                Console.WriteLine(user.GetOnlyMark());
                user.Address=DateTime.Now+ " a秦仕川a ";
                DBFactory.Update(user);
                 string name=DBFactory.GetOneField< string>(usersetTable.Address,usersetTable.ID.Equal(newID));
                List<userset> list=DBFactory.GetEntities<userset>(usersetTable.ID.BiggerThan( 0));
                Console.WriteLine(list[ 0].Address);
                Console.Read();
                
            }
        }
    }

     MYSQL.sql文件,自己還原下載

    View Code
    SET  @saved_cs_client      =  @@character_set_client;
    SET character_set_client  = utf8;
    /* !50001 CREATE TABLE `new_view` (
      `id` bigint(20),
      `username` varchar(50)
    ) ENGINE=MyISAM 
    */;
    SET character_set_client  =  @saved_cs_client;
    /* !40101 SET @saved_cs_client     = @@character_set_client  */;
    /* !40101 SET character_set_client = utf8  */;
    CREATE  TABLE `recordset` (
      `RecordID`  bigint( 20NOT  NULL AUTO_INCREMENT,
      `UserID`  bigint( 20NOT  NULL,
      `Sumary`  varchar( 1000NOT  NULL,
       PRIMARY  KEY (`RecordID`)
    ) ENGINE =InnoDB  DEFAULT CHARSET =latin1;
    /* !40101 SET character_set_client = @saved_cs_client  */;
    /* !40101 SET @saved_cs_client     = @@character_set_client  */;
    /* !40101 SET character_set_client = utf8  */;
    CREATE  TABLE `userset` (
      `UserName`  varchar( 50CHARACTER  SET utf8  DEFAULT  NULL,
      `Age`  int( 11DEFAULT  NULL,
      `ID`  bigint( 20NOT  NULL AUTO_INCREMENT,
      `Address`  varchar( 1000CHARACTER  SET utf8  DEFAULT  NULL,
       PRIMARY  KEY (`ID`)
    ) ENGINE =InnoDB AUTO_INCREMENT = 72  DEFAULT CHARSET =latin1;
    /* !40101 SET character_set_client = @saved_cs_client  */;
    INSERT  INTO `userset`  VALUES ( ' qsmy其實 ', 12, 1, NULL),( ' qsmy其實11 ', 12, 2, NULL),( ' qsmy其實11 ', 12, 3, NULL),( ' qsmy其實11 ', 12, 4, NULL),( ' qsmy其實11 ', 12, 5, NULL),( ' qsmy其實11 ', 12, 6, NULL),( ' qsmy其實11 ', 12, 7, NULL),( ' qsmy其實11 ', 12, 8, NULL),( ' qsmy其實11 ', 12, 9, NULL),( ' qsmy其實11 ', 12, 10, NULL),( ' qsmy其實11 ', 12, 11, NULL),( ' qsmy其實11 ', 12, 12, NULL),( ' qsmy其實11 ', 12, 13, NULL),( ' qsmy其實11 ', 12, 14, NULL),( ' qsmy其實11 ', 12, 15, NULL),( ' qsmy其實11 ', 12, 16, NULL),( ' qsmy其實11 ', 12, 17, NULL),( ' qsmy其實11 ', 12, 18, NULL),( ' qsmy其實11 ', 12, 19, NULL),( ' qsmy其實11 ', 12, 20, NULL),( ' qsmy其實11 ', 12, 21, NULL),( ' qsmy其實11 ', 12, 22, NULL),( ' qsmy其實11 ', 12, 23, NULL),( ' dd ', 123, 24, NULL),( ' dd ', 123, 25, NULL),( ' dd ', 123, 26, NULL),( ' dd ', 123, 27, NULL),( ' dd ', 123, 28, NULL),( ' dd ', 123, 29, NULL),( ' dd ', 123, 30, NULL),( ' dd ', 123, 31, NULL),( ' dd ', 123, 32, NULL),( ' dd ', 123, 33, NULL),( ' dd ', 123, 34, NULL),( ' dd ', 123, 35, NULL),( ' dd ', 123, 36, NULL),( ' dd ', 123, 37, NULL),( ' dd ', 123, 38, NULL),( ' dd ', 123, 39, NULL),( ' dd ', 123, 40, NULL),( ' dd ', 123, 41, NULL),( ' dd ', 123, 42, NULL),( ' dd ', 123, 43, NULL),( ' dd ', 123, 44, NULL),( ' dd ', 123, 45, NULL),( ' dd ', 123, 46, NULL),( ' aaa ', 11, 47, NULL),( ' aaa ', 11, 48, NULL),( ' aaa ', 11, 49, NULL),( ' aaa ', 11, 50, NULL),( ' aaa ', 11, 51, NULL),( ' aaa ', 11, 52, NULL),( ' aaa ', 11, 53, NULL),( ' aaa ', 11, 54, NULL),( ' qsmy12345 ', 12, 55, NULL),( ' qsmy12345634694104416406250 ', 12, 56, NULL),( ' qsmy12345634694105064218750 ', 12, 57, NULL),( ' 2012-4-7 15:49:36??? ', 12, 58, NULL),( ' 2012-4-7 15:52:45??? ', 12, 59, NULL),( ' 2012-4-7 15:54:34??? ', 12, 60, NULL),( ' 2012-4-7 15:55:01??? ', 12, 61, NULL),( ' 2012-4-7 15:56:44??? ', 12, 62, NULL),( ' 2012-4-7 15:57:56a???a ', 12, 63, NULL),( ' 2012-4-7 16:00:46a???a ', 12, 64, ' qsmy12345634694112457343750 '),( ' qsmy12345634694113184531250 ', 12, 65, ' 2012-4-7 16:01:59a???a '),( ' qsmy12345634694114936718750 ', 12, 66, ' 2012-4-7 16:04:54a秦仕川a '),( ' qsmy12345634694115219687500 ', 12, 67, ' 2012-4-7 16:05:22a秦仕川a '),( ' qsmy12345634694115920781250 ', 12, 68, ' 2012-4-7 16:06:32a秦仕川a '),( ' qsmy12345634694116243125000 ', 12, 69, ' 2012-4-7 16:07:05a秦仕川a '),( ' qsmy12345634694116477187500 ', 12, 70, ' 2012-4-7 16:07:28a秦仕川a '),( ' qsmy12345634694117010468750 ', 12, 71, ' 2012-4-7 16:08:21a秦仕川a ');
    /* !50001 DROP TABLE IF EXISTS `new_view` */;
    /* !50001 SET @saved_cs_client          = @@character_set_client  */;
    /* !50001 SET @saved_cs_results         = @@character_set_results  */;
    /* !50001 SET @saved_col_connection     = @@collation_connection  */;
    /* !50001 SET character_set_client      = utf8  */;
    /* !50001 SET character_set_results     = utf8  */;
    /* !50001 SET collation_connection      = utf8_general_ci  */;
    /* !50001 CREATE ALGORITHM=UNDEFINED  */
    /* !50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER  */
    /* !50001 VIEW `new_view` AS select `userset`.`ID` AS `id`,`userset`.`UserName` AS `username` from `userset`  */;
    /* !50001 SET character_set_client      = @saved_cs_client  */;
    /* !50001 SET character_set_results     = @saved_cs_results  */;
    /* !50001 SET collation_connection      = @saved_col_connection  */;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM