dbcontext - 非dbo所有者

时间:2013-11-30 08:29:51

标签: entity-framework schema dbo

我正在使用EF 5连接到我的桌子,但我的桌子没有dbo作为所有者。 EF 5查询将dbo插入为默认所有者。你能告诉我怎么改写这个吗?以下是一些代码段:

public class MessageBoardContext : DbContext
{
  public MessageBoardContext()
    : base("DefaultConnection")
  {

  this.Configuration.LazyLoadingEnabled = false;
  this.Configuration.ProxyCreationEnabled = false;

  Database.SetInitializer(
    new MigrateDatabaseToLatestVersion<MessageBoardContext, MessageBoardMigrationsConfiguration>()
    );
}

public DbSet<Topic> Topics { get; set; }
public DbSet<Reply> Replies { get; set; }

}

public class MessageBoardRepository : IMessageBoardRepository
{
  MessageBoardContext _ctx;
  public MessageBoardRepository(MessageBoardContext ctx)
  {
    _ctx = ctx;
  }

  public IQueryable<Topic> GetTopics()
  {
    return _ctx.Topics;  //Uses dbo.Topics here! Which I don't want.
  }
}

1 个答案:

答案 0 :(得分:1)

发现它!链接在这里: http://devproconnections.com/entity-framework/working-schema-names-entity-framework-code-first-design

以下是快速代码段:

public class OrderingContext : DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Customer>().ToTable("Customers", schemaName: "Ordering");

 }}