我想显示客户信息。 然后我创建了一些类;客户,交货,订单,OrderLine,产品和租赁DB。 rentalDB类设置5个DbSet的Product,Customer,Order,OrderLine和Delivery。 当我做UserController中与列表视图,我不能显示客户信息,并采取错误:ASP.NET MVC 3 EntityType没有定义密钥
One or more validation errors were detected during model generation:
System.Data.Edm.EdmEntityType: : EntityType 'OrderLine' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntityType: : EntityType 'Delivery' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �OrderLine� is based on type �OrderLine� that has no keys defined.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Delivery� is based on type �Delivery� that has no keys defined.
我不知道为什么这些企业需要的关键? 我不知道这个错误.. 你能帮我吗?
--UserController.cs--
namespace MvcApplication2.Controllers
{
public class UserController : Controller
{
//
// GET: /User/
rentalDB _db = new rentalDB();
public ActionResult Index()
{
var model = _db.Customer;
return View(model);
}
}
}
--Delivery.cs在模型folder--
namespace MvcApplication2.Models
{
public class Delivery
{
public int trackId { get; set; }
public String address { get; set; }
public String postCode { get; set; }
public decimal deliveryPrice { get; set; }
public DateTime deliveryDate { get; set; }
public DateTime returnDate { get; set; }
}
}
--OrderLine.cs在模型folder--
namespace MvcApplication2.Models
{
public class OrderLine
{
public int basketId { get; set; }
public int productId { get; set; }
public int quantity { get; set; }
}
}
这在特殊情况下适用于我。我在为模型编写代码后添加了一个控制器,但没有得到该错误。那时我意识到模型不是我想要的,意味着所有生成的视图都非常错误,所以我删除了控制器/视图。然后,当我修复模型并添加控制器时,出现错误。在搞乱了一个小时之后,我添加了[Key],它工作。也许视觉工作室Mvc奇怪或缓存,不知道... – isitdanny 2014-04-25 02:05:18