Open source data engine-Introduction (source code included), open source code

Source: Internet
Author: User

Open source data engine-Introduction (source code included), open source code

The NetUML. DataEngine Data Engine supports multiple databases. The data access engine adopts the configuration method, similar to the underlying principle of ibatis.net, and supports multi-database connection. In the future, database read/write splitting will be supported, and the read/write splitting configuration will adopt the MVC routing mechanism.

Source code structure

1 <provider name = "oracleManagedDataAccess" 2 description = "Oracle, Microsoft provider V1.0.5000.0" 3 enabled = "true" 4 default = "false" 5 assemblyName = "Oracle. managedDataAccess, Version = 4.121.1.0, Culture = neutral, PublicKeyToken = 89b483f429c47342"
ConnectionClass = "Oracle. managedDataAccess. client. oracleConnection "6 commandClass =" Oracle. managedDataAccess. client. oracleCommand "7 parameterClass =" Oracle. managedDataAccess. client. oracleParameter "8 parameterDbTypeClass =" Oracle. managedDataAccess. client. oracleDbType "9 parameterDbTypeProperty =" OracleType "10 dataAdapterClass =" Oracle. managedDataAccess. client. oracleDataAdapter "11 commandBuilderClass =" Oracle. managedDataAccess. client. oracleCommandBuilder "12 usePositionalParameters =" false "13 useParameterPrefixInSql =" true "14 useParameterPrefixInParameter =" false "15 parameterPrefix =": "16 allowMARS =" false "17/>

AssemblyName: information about the DLL Assembly used to access the database. This DLL file must also be placed in the program root directory.

App. Config configure the database connection string

<add providerName="oracleManagedDataAccess" name="oracle"  
connectionString="User ID=d;Password=d;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME=ORCL)));"/>

ProviderName: Specifies the configuration used to access the database. Here, the oracleManagedDataAccess configuration is used.

Ii. Initial Configuration

Call NetUML. DataAccess. DbHelper. InitDBConfig () when the program starts ();

Iii. Introduction

1. Create a table "Class1"

1/** create table [Class1] **/2 create table [dbo]. [Class1] (3 [ID] [int] IDENTITY (1, 1) not null, 4 [aa] [nvarchar] (50) NULL, 5 [bb] [datetime] NULL, 6 [cc] [bit] NULL, 7 [ee] [int] NULL, 8 CONSTRAINT [PK_Class1] primary key 9 (10 [ID] ASC11) WITH (PAD_INDEX = OFF, rows = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 12) ON [PRIMARY] 13 GO

 

2. generate "ClassModel"

 1     ///<summary> 2     ///Class1 3     ///<summary>     4     [Table("Class1")] 5     public class ClassModel: NetUML.DataEngine.ActiveEntity 6     { 7          8         /// <summary> 9         /// [ID]10         /// </summary>11         [Key(KeyType.Indentity)]12         public int ID13         {14           get;set;15         }16         private string _aa;17         /// <summary>18         /// [aa]19         /// </summary>20         public string aa21         {22           set23           {24               if (_aa == value) return;25               OnChanged("aa", _aa, value);26               _aa = value;27           }28           get { return  _aa;}29         }30         private DateTime? _bb;31         /// <summary>32         /// [bb]33         /// </summary>34         public DateTime? bb35         {36           set37           {38               if (_bb == value) return;39               OnChanged("bb", _bb, value);40               _bb = value;41           }42           get { return  _bb;}43         }44         private bool? _cc;45         /// <summary>46         /// [cc]47         /// </summary>48         public bool? cc49         {50           set51           {52               if (_cc == value) return;53               OnChanged("cc", _cc, value);54               _cc = value;55           }56           get { return  _cc;}57         }58         private int? _ee;59         /// <summary>60         /// [ee]61         /// </summary>62         public int? ee63         {64           set65           {66               if (_ee == value) return;67               OnChanged("ee", _ee, value);68               _ee = value;69           }70           get { return  _ee;}71         }72     }

The new table and Model generation code are both generated using DataUML software, such:

1 // Add data 2 ClassModel model = new ClassModel (); 3 model. aa = "ss"; 4 model. bb = DateTime. now; 5 model. save (); 6 // modify data 7 ClassModel model = new ClassModel (); 8 model. ID = 1; 9 model. aa = "bb"; 10 model. update (); 11 // delete data 12 ClassModel model = new ClassModel (); 13 model. ID = 1; 14 model. delete ();4. multi-database connection

The configuration information of the app. config database is as follows:

   <add providerName="oracleManagedDataAccess" name="oracle"  connectionString="User ID=a;Password=a;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCL)));"/>    <add providerName="sqlServer2.0"  name="sqlconnect1" connectionString="Data Source=192.168.0.1;Initial Catalog=t;User Id=sa;Password=sa" />    <add providerName="sqlServer2.0"  name="sqlconnect2" connectionString="Data Source=192.168.0.1;Initial Catalog=t;User Id=sa;Password=sa" />    

The Model information is as follows.

1 // <summary> 2 // use the "sqlconnect1" database connection string to read and write data 3 // <summary> 4 [Table ("Class1 ", connectionName = "sqlconnect1")] 5 public class ClassModel: NetUML. dataEngine. activeEntity 6 {7 [Key (KeyType. indentity)] 8 public int ID 9 {10 get; set; 11} 12}

When reading and writing data

<Add providerName = "sqlServer2.0" name = "sqlconnect1" connectionString = "Data Source = 192.168.0.1; Initial Catalog = t; User Id = sa; Password = sa"/>

This database connection string.
V. Subsequent Updates
1. added the read/write splitting configuration and multi-database operation configuration. You do not need to define the ConnectionName attribute on the class and set it in configuration mode.
2. added the object-oriented concept, the ing between classes, and cascade operations.
3. Add more query operations
4 ,..........


Source code download

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.