Answer the question
In order to leave comments, you need to log in
'System.Data.Entity.DbSet' does not contain a definition for 'Id'. What is the problem?
Visual Studio 2015
(actually Books)
HomeController:
BookContext db = new BookContext();
// GET: Home
public ActionResult Index()
{
return View(db.Books);
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
@{
ViewBag.Title = "Index";
Layout = "~/Views/_Layout.cshtml";
}
@Model WebApplication4.Models.Books
<h2>Книга № @Model.Id</h2>
@Html.DisplayForModel()
public class Book
{
public int Id { get; set; }
public string Name { get; set; }
public string Author { get; set; }
public int Price { get; set; }
}
public class BookContext :DbContext
{
public BookContext() : base("BookContext")
{ }
public DbSet<Book> Books { get; set; }
public DbSet<Purchase> Purchases { get; set; }
}
<add name="BookContext" connectionString="Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Bookstore.mdf;Integrated Security=True; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" /> </connectionStrings>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question