FreeSql (a) entry

FreeSql is a powerful NETStandard library for object-relational mapper (O / RM), so that developers can use .NETStandard object to handle the database without having to write most often data access code.

FreeSql using MIT open source license hosted on github.

characteristic

  • [X] support CodeFirst migration;
  • [X] support DbFirst introduced entity classes from the database, supports three template generator;
  • [X] ExpressionTree using high performance read data;
  • [X] support in-depth type mapping, such as arrays of type pgsql, called the ingenuity production;
  • [X] supports a rich expression functions;
  • [X] attribute query navigation support, and delay loading;
  • [X] supports synchronous / asynchronous database operation method, a variety of chain query method;
  • [X] support separate read and write, sub-sub-table repository, tenant design;
  • [X] supports multiple databases, MySql / SqlServer / PostgreSQL / Oracle / Sqlite;

model

Perform data access using the model, the model represents a physical database table or view classes, to query and store data.

Solid model can be generated from an existing database, FreeSql interface provides IDbFirst green create a solid model .

Or manually create the model, the model-based API to create or modify a database, providing ICodeFirst synchronization structure (development phase can even do automatic synchronization).

using FreeSql.DataAnnotations;
using System;

public class Blog
{
    [Column(IsIdentity = true, IsPrimary = true)]
    public int BlogId { get; set; }
    public string Url { get; set; }
    public int Rating { get; set; }
}

statement

dotnet add packages FreeSql.Provider.Sqlite

var connstr = @"Data Source=|DataDirectory|\db1.db;Attachs=db2.db;Pooling=true;Max Pool Size=10";

IFreeSql fsql = new FreeSql.FreeSqlBuilder()
    .UseConnectionString(FreeSql.DataType.Sqlite, connstr)
    .UseAutoSyncStructure(true) //自动同步实体结构到数据库
    .Build();

Note: IFreeSql should singleton statement in the project in order to, rather than in the time of each use.

migrate

Running the program checks AutoSyncStructure FreeSql parameters, this condition is determined whether or not changes in contrast between the entity and the database structure, to achieve automatic migration.

Inquire

var blogs = fsql.Select<Blog>()
    .Where(b => b.Rating > 3)
    .OrderBy(b => b.Url)
    .Skip(100)
    .Limit(10) //第100行-110行的记录
    .ToList();

insert

var blog = new Blog { Url = "http://sample.com" };
blog.BlogId = (int)fsql.Insert<Blog>()
    .AppendData(blog)
    .ExecuteIdentity();

Update

fsql.Update<Blog>()
    .Set(b => b.Url, "http://sample2222.com")
    .Where(b => b.Url == "http://sample.com")
    .ExecuteAffrows();

delete

fsql.Delete<Blog>()
    .Where(b => b.Url == "http://sample.com")
    .ExecuteAffrows();

Guess you like

Origin www.cnblogs.com/FreeSql/p/11531300.html