Dapper Extensions Change Schema

假如想象 提交于 2019-12-07 06:24:22

问题


I am using Dapper Extensions to do some simple CRUD operations on a DB. My problem is that the tables I am using are held in a different schema to dbo. Is there a way to choose the schema at the dapper extensions level?

or

Should this be dealt with via the user that is being used to connect to the db with?


回答1:


You can use the AutoClassMapper to assign a new schema to your model. An overview on this is on the extensions site. You will basically need to create an AutoClassMapper per model with a different schema. The best place to declare it is alongside your model itself like:

public class MyModel 
{
  public Guid Id { get; set; } 
}

public class MyModelMapper : AutoClassMapper<MyModel>
{
  public MyModelMapper() : base()
  {
    Schema("YourNewSchema");
  }
}


来源:https://stackoverflow.com/questions/20399710/dapper-extensions-change-schema

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