gpt4 book ai didi

c# - 如何将我的 MVC 模型绑定(bind)到不同的表

转载 作者:行者123 更新时间:2023-11-30 21:10:04 24 4
gpt4 key购买 nike

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

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

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。如何将此路由更改为实际表?

最佳答案

将此添加到您的 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"
}
}

关于c# - 如何将我的 MVC 模型绑定(bind)到不同的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8682993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com