The benefits of LINQ are very obvious, not only the database access layer is really object-oriented, but also the system's permissions can be encapsulated into the database access layer.
Microsoft's current stable LINQ framework is the Entity Framework 6.1, I have written a database tool MR.E, can be used to design the database structure, and the database structure into the Entity framework of the object, can be said to be automated code First mode.
MR.E runs in the. Net 4.5 version, presumably with the following features:
1. Network version, support multi-person design database at the same time;
2. Currently supports SQL Server, MYSQL, SQLite database;
3. Support database structure update;
---your project is published, if you modify the database structure again, you can use MR.E to structure updates to the published database.
4. Support database type change;
---such as the original SQL Server database, can be changed in the middle of development to the MySQL database, without the need to change the code.
5. Support a database structure, multiple database types;
---such as your project, it is divided into web and stand-alone version, the network version of the SQL Server database, single-use SQLite database, then you can continue to SQL Server type database structure design, to release the time, Update the structure to another SQLite database.
6. Turn off EF's data tracking to improve performance
7. Support similar trigger code, through code, can capture the global data table Insert Update Delete event;
---, it's equivalent to writing triggers in C #.
8. Support for defining indexes
9. Support Cascade Delete, cascade deleted data also support 7 inside features
Need MR.E source of friends can add my QQ request. (896872647)
Installation steps:
1. Configure the IIS Service site for MR.E
Click Download Ecweb.rar file, unzip, create a website in IIS to execute it, the port can be arbitrarily defined, for example: 666, the application pool must be. Net 4.5 or later
2. Download the client
Download Mr.e.rar file, unzip, directly run EJClient.exe, pop-up Login window, enter the previous step IIS inside the configured Web site path, user name default: SA, password is: 1
3. Create a Database
First, you need to create a new project, click the Menu "Project", create a new project
Then, expand the new project, right-click on databases, and create a new database
Note: If you have a SQLite type database, such as a database in F:\SqliteLinqTest, you must confirm that IIS has read-write F:\SqliteLinqTest folder permissions, or you cannot create
3. Create a data table
Right-click on the "Data module", add a directory, and add a module underneath the directory
----->
Then double-click on the "Basic info" module to add the data table in its area. In this way, the data tables can be categorized and managed, unlike SQL Server, where all tables are listed together
--->
4. Compiling the database, generating the DLL file
Right-click on testdb-> "compile" to generate its DLL file.
5. Accessing the database in code
Download common DLL files Entitydb.rar
Create a new one. NET project, referring to EntityDB.dll, EntityFramework.dll, just generated TestDBDataObjects.dll,. NET comes with the System.Data.Linq
After compiling the project, we need to copy all the DLLs inside the Entitydb.rar, including the x86 x64 folder, to the running directory, bin\debug below, which are all required by the runtime.
Here's the code for C # access to the database
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Diagnostics;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacelinqtest1{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidForm1_Load (Objectsender, EventArgs e) { using(vardb =NewTest.DB.TestDB (@"data source= "" F:\SqliteLinqTest\TestDB """, EntityDB.DatabaseType.Sqlite)) { //Start a transactiondb. BeginTransaction (); Try { //Add Data varuser =NewTest.userinfo (); User. UserName="Zhang San"; User. Password="123"; Db. Update (user); Debug.WriteLine ("The ID of the Zhang San is"+user.id); //Update Data varZhangsan = ( fromMinchdb. UserInfowhereM.username = ="Zhang San" Selectm). FirstOrDefault (); Zhangsan.password="678"; Db. Update (Zhangsan); //Delete Data vardata = db. Userinfo.firstordefault (m = M.username = ="John Doe"); if(Data! =NULL) {db. Delete (data); } //Commit a transactiondb.committransaction (); } Catch { //rolling back a transactiondb. RollbackTransaction (); Throw; } } } }}
As you can see from the code, because I turned off the EF data tracking, the Insert update Delete for the data, and so on, required a call to DB. Update () db. Delete () To implement, can't do it with EF's own way
. NET open source database design tool MR.E for LINQ (EF 6.1) tutorial (i)