FreeSql (四)实体特性 Fluent Api

FreeSql 提供使用 Fluent Api, 在外部配置实体的数据库特性,Fluent Api 的方法命名与特性名保持一致,以下:html

fsql.CodeFirst
    .ConfigEntity<TestFluenttb1>(a => {
        a.Name("xxdkdkdk1").SelectFilter("a.Id22 > 0");
        a.Property(b => b.Id).Name("Id22").IsIdentity(true);
        a.Property(b => b.name).DbType("varchar(100)").IsNullable(true);
    })
    .ConfigEntity<TestFluenttb2>(a => {
        a.Name("xxdkdkdk2").SelectFilter("a.Idx > 0");
        a.Property(b => b.Id).Name("Id22").IsIdentity(true);
        a.Property(b => b.name).DbType("varchar(100)").IsNullable(true);
    });

//如下为实体类
class TestFluenttb1
{
    public int Id { get; set; }
    public string name { get; set; } = "defaultValue";
}

[Table(Name = "cccccdddwww")]
class TestFluenttb2
{
    public int Id { get; set; }

    public string name { get; set; } = "defaultValue";
}

fsql 是一个 IFreeSql 对象sql

优先级

FluentApi < 实体特性数据库

系列文章导航