I have this error
Invalid object name '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:
public System.Data.Entity.DbSet<SmartSolutions.Models.Vacancy> Vacancies { get; set; }
Here is code of View where I try to show data from table.
// GET: VacanciesAll
public ActionResult Index()
{
var vacancies = db.Vacancies.Include(v => v.Company);
return View(vacancies.ToList());
}
请检查EF图层[SSDL - CSDL - MSL]这是您的EF图层和数据库引擎之间的冲突
It could be loooking at the wrong database.
The DbContext class should match the name in the connection string.
Make sure your connection string "name" property is correct.
Example: PortalEntities DbContext should match PortalEntities in connectionStrings.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.