preface
Beijing Renmin Jincang Information Technology Co., Ltd. (hereinafter referred to as "Renmin Jincang") is a domestic data management software and service provider with independent intellectual property rights. Founded in 1999 by a group of experts from Renmin University of China who are the first to carry out database teaching, scientific research and development in China, Jincang has successively undertaken the national "863" and "nuclear high base" major projects and developed large-scale universal database products with international advanced level. In 2018, the project of "innovation of core technology of database management system and industrialization of Jincang database" declared by Jincang of the people's Congress won the second prize of national science and technology progress in 2018, and the integration of industry, University and research further helped the national informatization construction.
With Huawei and ZTE affairs, 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 people's Congress Jincang database is almost 0. Today, we use FreeSql ORM to experience the domestic people's Congress Jincang database (although it is modified with pgsql source code).
Generally speaking, Renmin Jincang 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: kingcases V8
Download address: https://www.kingbase.com.cn/index/service/c_id/212.html
. NET version:. net core 3.1
Download address: https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install
Development machine: windows 10
ODBC driver:
At present, only ODBC driver can be used to access the database of Renmin Jincang database. If Kingbase V8 is successfully installed, then we can check the system ODBC. Normally, it will display as follows:
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.Odbc --version 1.6.0-preview0102
dotnet add package FreeSql.Repository --version 1.6.0-preview0102
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.OdbcKingbaseES, "Driver={KingbaseES 8.2 ODBC Driver ANSI};Server=127.0.0.1;Port=54321;UID=USER2;PWD=123456789;database=TEST") .UseMonitorCommand(cmd => Trace.WriteLine($"Thread:{cmd.CommandText}rn")) .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 = "kingbase1", PassWord = "123" }; repo.Insert(user);
var users = new [] { new User { UserName = "kingbase2", PassWord = "1234" }, new User { UserName = "kingbase3", PassWord = "12345" }, new User { UserName = "kingbase4", 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("kingbase")).ToList();
8. Delete data
fsql.Delete<User>(1).ExecuteAffrows(); fsql.Delete<User>().Where(a => a.UserName.StartsWith("kingbase")).ExecuteAffrows();
epilogue
This article briefly introduces the access of FreeSql to the domestic people's Congress Jincang database 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 / daydream, as well as Renmin Jincang database. In the future, it will access more domestic database support.
Source address: https://github.com/2881099/FreeSql
Thank you for your support!