简体   繁体   English

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

[英]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: 这是表: 在此输入图像描述

Here is the table in EF 这是EF中的表格 在此输入图像描述 Why am I getting an error? 为什么我收到错误?

Check if the Table exists in your Sql Database. 检查Sql数据库中是否存在表。 Chances are it is not there in your Database, hence, the error. 有可能它在您的数据库中没有,因此,错误。

在此输入图像描述

If the table exists, make sure you are mapping your EF table to the correct table name in DbContext. 如果表存在,请确保将EF表映射到DbContext中的正确表名。

请检查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.

相关问题 ASP.NET MVC 5无效的对象名称&#39;dbo.UsersInRoles&#39; - ASP.NET MVC 5 Invalid object name 'dbo.UsersInRoles' Asp.net mvc 错误 System.Data.SqlClient.SqlException:'无效的 object 名称'AspNetUsers'。 - Asp.net mvc error System.Data.SqlClient.SqlException: 'Invalid object name 'AspNetUsers'.' 无效的对象名称&#39;dbo.UserNotes&#39;。 异常 - ASP.NET MVC 4 - Invalid object name 'dbo.UserNotes'. exception - ASP.NET MVC 4 C#无效的对象名称ASP.NET - C# Invalid object name ASP.NET ASP.NET MVC 5“ ModelState无效时” - ASP.NET MVC 5 “When ModelState is Invalid” ASP.Net MVC 登录尝试无效 - ASP.Net MVC Invalid login attempt 无效的JSON原语-Asp.Net MVC 4 - Invalid JSON primitive - Asp.Net MVC 4 ASP.NET MVC /实体框架错误 - 无效的列名称&#39;Environment_Id&#39; - ASP.NET MVC /Entity Framework Error - Invalid column name 'Environment_Id' 使用实体框架代码优先的ASP.NET MVC 3 Web应用程序上的列名ProveedoresID和UsuarioID无效 - Invalid column name ProveedoresID and UsuarioID on ASP.NET MVC 3 web app using Entity Framework Code First ASP.NET MVC3自定义成员资格提供程序 - 指定的成员资格提供程序名称无效 - ASP.NET MVC3 Custom Membership Provider - The membership provider name specified is invalid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM