我正在使用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.
}
}
答案 0 :(得分:1)
以下是快速代码段:
public class OrderingContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Customer>().ToTable("Customers", schemaName: "Ordering");
}}