问题
No clue why I'm getting this error in my ASP MVC application:
'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:
My create view is working just fine, and submitting what I enter into it inside the database, so I think my connection string is fine.
Here's my model:
namespace MICSgroupHospital.Models
{
[Table("THEMES")]
public class Theme
{
public int Id { get; set; }
public string Hex { get; set; }
}
}
Here's my context class:
namespace MICSgroupHospital.Models
{
public class ThemeContext : DbContext
{
public DbSet<Theme> themeContext { get; set; }
}
}
Here's the culprit action in my controller (the controller was auto generated, as well as the views):
public ActionResult Index()
{
return View(db.themeContext.ToList());
}
The connection string:
<add name="ThemeContext" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\ThemeDB.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
Any thoughts would be greatly appreciated...
edit: Still no luck. I've tried recreating the database connection.
来源:https://stackoverflow.com/questions/36436555/context-is-not-a-member-of-transient-collection