[英]Invalid object name (ASP.NET MVC)
I have this error 我有这个错误
Invalid object name 'dbo.Vacancies' 无效的对象名称'dbo.Vacancies'
But I have Model for Vacancies. 但我有空缺模型。
Here it is: 这里是:
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; }
}
} }
Also I have table Vacancy. 我也有桌子空缺。
This code I have in IdentityModels: 这个代码我在IdentityModels中有:
public System.Data.Entity.DbSet<SmartSolutions.Models.Vacancy> Vacancies { get; set; }
Here is code of View where I try to show data from table. 这是我尝试从表中显示数据的View代码。
// GET: VacanciesAll
public ActionResult Index()
{
var vacancies = db.Vacancies.Include(v => v.Company);
return View(vacancies.ToList());
}
Here is the table in EF 这是EF中的表格 Why am I getting an error? 为什么我收到错误?
请检查EF图层[SSDL - CSDL - MSL]这是您的EF图层和数据库引擎之间的冲突
It could be loooking at the wrong database. 它可能在错误的数据库中徘徊。
The DbContext class should match the name in the connection string. DbContext类应与连接字符串中的名称匹配。
Make sure your connection string "name" property is correct. 确保您的连接字符串“name”属性正确。
Example: PortalEntities DbContext should match PortalEntities in connectionStrings. 示例:PortalEntities DbContext应与connectionStrings中的PortalEntities匹配。
public class PortalEntities : DbContext
{
public DbSet<Delegate> Delegates { get; set; }
public DbSet<Status> Statuses { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<PortalEntities>(null);
base.OnModelCreating(modelBuilder);
}
}
<connectionStrings>
<add name="PortalEntities" connectionString="Data Source=serverName;Integrated Security=true;Initial Catalog=dbName;" providerName="System.Data.SqlClient"/>
</connectionStrings>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.