. NETCore ORM visit domestic daydream database

Keywords: ASP.NET Database odbc Oracle Big Data

Preface

Founded in 2000, Wuhan Dameng database Co., Ltd. is a basic software enterprise under China Electronic Information Industry Group (CEC). It specializes in the research and development, sales and service of database management system, and provides users with services such as big data platform architecture consultation, data technology plan, product deployment and implementation. Over the years, daydream has always adhered to original innovation and independent research and development. At present, it has mastered the core and cutting-edge technology in the field of data management and data analysis, with all the source code and full independent intellectual property rights.

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 domestic daydream database is almost 0. Today, we use FreeSql ORM to experience the domestic daydream database.

Overall, Damien 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: DM8

Download address: http://www.dameng.com/down.as...:11:14

. NET version:. net core 3.1

Download address: https://dotnet.microsoft.com/...

Development machine: windows 10

ODBC driver:

At present, daydream database can only use ODBC driver to access the database. If DM8 is installed successfully, 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

dotnet add package FreeSql.Repository

3. Create entity 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.OdbcDameng, 
    "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;UID=USER1;PWD=123456789")
    .UseMonitorCommand(cmd => Trace.WriteLine($"Threading:{cmd.CommandText}\r\n"))
    .UseAutoSyncStructure(true) //Automatically create and migrate entity table structure
    .UseSyncStructureToUpper(true)
    .Build();

5. Insert data

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

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

var users = new []
{
    new User { UserName = "dm2", PassWord = "1234" },
    new User { UserName = "dm3", PassWord = "12345" },
    new User { UserName = "dm4", PassWord = "123456" }
};
repo.Insert(users);
//Batch insertion

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("dm")).ToList();

8. Delete data

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

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

epilogue

This article briefly introduces the access of FreeSql to domestic daydream database in. 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, as well as daydream database. In the future, it will access more domestic database support.

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

Thank you for your support!

Posted by frontlines on Thu, 12 Dec 2019 23:14:09 -0800