不知道为什么我在ASP MVC应用程序中出现此错误:
'themeContext' is not a member of 'Transient.collection[MICSgroupHospital.Models.Theme(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a sub-query to iterate over the collection. Near escaped identifier, line 1, column 16.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.Entity.Core.EntitySqlException: 'themeContext' is not a member of 'Transient.collection[MICSgroupHospital.Models.Theme(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a sub-query to iterate over the collection. Near escaped identifier, line 1, column 16.
Source Error:
Line 18: public ActionResult Index()
Line 19: {
Line 20: return View(db.themeContext.ToList());
Line 21: }
Line 22:
我的创建视图工作正常,并在数据库中提交我输入的内容,所以我认为我的连接字符串很好。
这是我的模特:
namespace MICSgroupHospital.Models
{
[Table("THEMES")]
public class Theme
{
public int Id { get; set; }
public string Hex { get; set; }
}
}
这是我的上下文类:
namespace MICSgroupHospital.Models
{
public class ThemeContext : DbContext
{
public DbSet<Theme> themeContext { get; set; }
}
}
这是我控制器中的罪魁祸首(控制器是自动生成的,以及视图):
public ActionResult Index()
{
return View(db.themeContext.ToList());
}
连接字符串:
<add name="ThemeContext" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\ThemeDB.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
任何想法都会非常感激......
编辑:仍然没有运气。我已经尝试重新创建数据库连接。