【发布时间】:2011-02-20 15:48:26
【问题描述】:
有一个名为 Northwind 的现有数据库,其中包含一个 Web 表单应用程序。 运行应用程序时出现错误: '无效的列名 CategoryCategoryID'。 任何人帮助我? 提前谢谢!!
Category.cs:
public class Category
{
public int CategoryID { get; set; }
// public int ID { get; set; }
public string CategoryName { get; set; }
public string Description { get; set; }
public byte[] Picture { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
Product.cs:
public class Product
{
public int ProductID { get; set; }
//public int ID { get; set; }
public string ProductName { get; set; }
public Decimal? UnitPrice { get; set; }
public bool Discontinued{ get; set; }
public virtual Category Category{ get; set; }
}
Northwind.cs
public class Northwind: DbContext
{
public DbSet< Product > Products { get; set; }
public DbSet< Category > Categorys{ get; set; }
}
Products.aspx
protected void Page_Load(object sender, EventArgs e)
{
Northwind northwind = new Northwind();
var products = from p in northwind.Products
where p.Discontinued == false
select p;
GridView1.DataSource = products.ToList();
GridView1.DataBind();
}
【问题讨论】:
-
你为什么评论 Id?可能架构不匹配
标签: entity-framework ef-code-first