gpt4 book ai didi

c# - 无效的对象名称 (ASP.NET MVC)

转载 作者:行者123 更新时间:2023-11-30 15:58:41 25 4
gpt4 key购买 nike

我有这个错误

Invalid object name 'dbo.Vacancies'

但我有职位空缺模型。

这里是:

public partial class Vacancy
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Vacancy()
{
this.Interwiers = new HashSet<Interwier>();
this.InvitationMails = new HashSet<InvitationMail>();
}

[Key]
public int Vacancy_Id { get; set; }
[Display(Name="Вакансия")]
public string VacancyName { get; set; }
public Nullable<int> CompanyID { get; set; }

public virtual Company Company { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Interwier> Interwiers { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<InvitationMail> InvitationMails { get; set; }
}

我还有空位表。

我在 IdentityModels 中的这段代码:

public System.Data.Entity.DbSet<SmartSolutions.Models.Vacancy> Vacancies { get; set; }

这是我尝试显示表中数据的 View 代码。

// GET: VacanciesAll
public ActionResult Index()
{
var vacancies = db.Vacancies.Include(v => v.Company);
return View(vacancies.ToList());
}

这是表格: enter image description here

这是EF中的表 enter image description here为什么会出现错误?

最佳答案

检查该表是否存在于您的 SQL 数据库中。可能它不在您的数据库中,因此出现错误。

enter image description here

如果表存在,请确保将 EF 表映射到 DbContext 中的正确表名。

关于c# - 无效的对象名称 (ASP.NET MVC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42758122/

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