【问题标题】:How can I bind my MVC Model to a different table如何将我的 MVC 模型绑定到不同的表
【发布时间】:2011-12-31 04:00:00
【问题描述】:

这似乎是一个简单的问题,但我似乎找不到答案。

我有一个看起来像这样的模型......

public class Application
{

    public int Id { get; set; }
    public string Title { get; set; }
    public string LeadProgrammer { get; set; }
    public string ConnectionStringCode { get; set; }
}

public class ApplicationDBContext : DbContext
{
    public DbSet<Application> Applications { get; set; }
}

我的实际表名是 DBA_APPLICATIONS ... 当然,模型只是在寻找 dbo.Applications。如何将此路由更改为实际表?

【问题讨论】:

标签: c# asp.net asp.net-mvc entity-framework


【解决方案1】:

将此添加到您的 ApplcationDBContext 课程中。

public class ApplicationDBContext : DbContext
{
    public DbSet<Application> Applications { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Application>().ToTable("DBA_APPLICATIONS");
        // otherwise EF assumes the table is called "Applications"
    }
}

【讨论】:

    猜你喜欢
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多