[open source]. Net uses ORM to access Shenzhou general database (Shentong)

Keywords: Programming Database Oracle Big Data PHP

preface

Tianjin Shenzhou General Data Technology Co., Ltd. (hereinafter referred to as "Shenzhou general company") is subordinate to China Aerospace Science and Technology Corporation (CASC). Is engaged in the domestic database, big data solutions and data mining analysis product research and development of professional companies. The company has obtained the key support of national nuclear high-tech major special projects and is the leading undertaking unit of nuclear high-tech special projects. Since 1993, Shentong database has been developing for 27 years. The company's core products mainly include the R & D and marketing of Shentong relational database, Shentong KStore mass data management system, Shentong Business Intelligence Suite and other series of products. Based on the product portfolio, solutions can be formed to support transaction processing, MPP database clustering, data analysis and processing, etc., which can meet the needs of a variety of application scenarios. The products have passed the security evaluation and certification of the classified information system of the State Security Bureau, the fourth level of the Ministry of public security and the B + level of the military.

With Huawei and ZTE, the domestic database market is believed to be the trend in the future. Throughout the whole circle of. net core, the support for the domestic Shenzhou universal database (Shentong) is almost 0. Today, we use FreeSql ORM to experience the domestic Shenzhou universal database (Shentong).

On the whole, Shenzhou universal database (Shentong) has 90% compatibility with Oracle syntax, but there are still some details to be noted. FreeSql has made perfect support for this optimization.

1. Installation environment

Database server: ShenTong7.0.8

Download address: http://www.shentongdata.com/index.php/download/list-27

. NET version:. net core 3.1

Download address: https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install

Development machine: windows 10

2. Create project

We use the console type project to test the insertion, deletion, update, query and other functions, create a console project, and use the command:

dotnet new console

dotnet add package FreeSql.Provider.ShenTong

dotnet add package FreeSql.Repository --version 1.6.0

3. Create a solid model

using System;
using FreeSql.DataAnnotations;

public class User
{
    [Column(IsIdentity = true)]
    public long Id { get; set; }

    public string UserName { get; set; }

    public string PassWord { get; set; }

    public DateTime CreateTime { get; set; }
}

4. Initialize ORM

static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
    .UseConnectionString(FreeSql.DataType.ShenTong, 
    "HOST=192.168.164.10;PORT=2003;DATABASE=OSRDB;USERNAME=SYSDBA;PASSWORD=szoscar55;MAXPOOLSIZE=2")
    .UseMonitorCommand(cmd => Trace.WriteLine($"Thread:{cmd.CommandText}\r\n"))
    .UseAutoSyncStructure(true) //Automatically create and migrate entity table structure
    .UseNameConvert(NameConvertType.ToUpper)
    .Build();

5. Insert data

var repo = fsql.GetRepository<User>();

var user = new User { UserName = "shentong1", PassWord = "123" };
repo.Insert(user);

var users = new []
{
    new User { UserName = "shentong2", PassWord = "1234" },
    new User { UserName = "shentong3", PassWord = "12345" },
    new User { UserName = "shentong4", PassWord = "123456" }
};
repo.Insert(users);
//Bulk insert

6. Update data

user.PassWord = "123123";
repo.Update(user);

7. Query data

var one = fsql.Select<User>(1).First(); //Query a piece of data

var list = fsql.Select<User>().Where(a => a.UserName.StartsWith("shentong")).ToList();

8. Delete data

fsql.Delete<User>(1).ExecuteAffrows();

fsql.Delete<User>().Where(a => a.UserName.StartsWith("shentong")).ExecuteAffrows();

epilogue

This article briefly introduces the access of FreeSql to the domestic Shenzhou universal database (Shentong) in the. net core 3.1 environment. At present, FreeSql also supports the use of. net framework 4.0 and xamarin platform.

In the future, the domestic database will be the development trend, and the ownership will not be limited by others. I have seen in several groups that the company is preparing to fully use the domestic system + domestic database.

In addition to adding, deleting, checking and modifying, FreeSql also supports many functions, so it can't be demonstrated one by one and can't be covered in one article.

FreeSql is an ORM open source project under the platform of. NETCore/.NetFramework/Xamarin. It supports SqlServer/MySql/PostgreSQL/Oracle/Sqlite / Damin / Renmin Jincang, as well as Shenzhou universal database (Shentong). In the future, it will be supported by more domestic databases.

Source address: https://github.com/2881099/FreeSql

Thank you for your support!

Posted by cbailster on Sat, 27 Jun 2020 17:55:00 -0700