FreeSql (四)实体特性 Fluent Api

梦想的初衷 提交于 2019-12-01 14:16:49

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

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 对象

优先级

FluentApi < 实体特性

系列文章导航

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

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 对象

优先级

FluentApi < 实体特性

系列文章导航

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!