zoukankan      html  css  js  c++  java
  • 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; }
    }
    
  • 相关阅读:
    配置 Sublime Text 用 Node.js 执行 JavaScript 程序
    KNN算法
    堆排序(heap sort)
    复原二叉树
    二叉树的广度优先遍历(层次遍历)
    二叉树(BT)相关
    BST(二叉搜索树)相关
    二叉树遍历(先序、中序、后序)
    排序算法
    查找算法
  • 原文地址:https://www.cnblogs.com/dupeng0811/p/dapperextensions-and-dapper-contrib-with-non-dbo-schema.html
Copyright © 2011-2022 走看看