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


    什么是数据库的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; }
    }
    
  • 相关阅读:
    js数组的基本用法及数组根据下标(数值或字符)移除元素
    Oracle备份一张表
    linux中常见的文件操作命令
    java图片二进制相互转换
    getParameterMap的使用
    前端常用
    Oracle 常用
    JAVA中int、String的类型转换
    MySQL 5.7 新特性大全和未来展望
    你有自己的Web缓存知识体系吗?
  • 原文地址:https://www.cnblogs.com/dupeng0811/p/dapperextensions-and-dapper-contrib-with-non-dbo-schema.html
Copyright © 2020-2023  润新知