DapperExtensions and Dapper.Contrib在表构架不是默认dbo时的处理 DapperExtensions and Dapper.Contrib with non-dbo...

什么是数据库的Schema

dbo是一个构架(schema),与sql2000不同的是,在sql2005中,表的调用格式如下:"数据库名.构架名.表名",同一个用户可以被授权访问多个构架,也可以被禁止访问某个或多个构架,这就是2005中提倡的"用户与构架分离"的概念.在2005中,如果在创建表时没有指定构架(schema),那么系统默认该表的构架是dbo,所以会出现很多表名前自动加上dbo.字符样式.

DapperExtensions 下的方法

Using the built in ClassMapper, you can customize the mapping for a specific entity.

public class MyModelMapper : ClassMapper<MyModel>
{
    public MyModelMapper()
    {

        //use different table name
        Table("table_name");

        //use a custom schema
        Schema("not_dbo_schema"); 

        //have a custom primary key
        Map(x => x.ThePrimaryKey).Key(KeyType.Assigned);

        //Use a different name property from database column
        Map(x=> x.Foo).Column("Bar");

        //Ignore this property entirely
        Map(x=> x.SecretDataMan).Ignore();

        //optional, map all other columns
        AutoMap();
    }
}

Dapper.Contrib下的方法

You can use Table attribute to show schema and table name together with a dot in between:

using Dapper.Contrib.Extensions;

[Table ("vehicles.YourTables")]
public class YourClass
{
    public int Id { get; set; }
    public string Name { get; set; }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值