ASP.NET MVC 3 EntityType has no key defined

前端 未结 2 1656
南笙
南笙 2021-01-12 18:33

I want to display customer information. Then I created some classes; Customer, Delivery, Order, OrderLine, Product, and rentalDB. rentalDB class sets 5 DbSet of Product, Cus

2条回答
  •  春和景丽
    2021-01-12 19:16

    In order to use the entity framework, every entity needs a key. This is how EF tracks objects in its cache, posts updates back to the underlying data store, and links related objects together.

    Yours objects already have keys, you just need to tell the EF about them:

    namespace MvcApplication2.Models
    {
      public class Delivery
      {
        [Key] 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; }
      }
    }
    

提交回复
热议问题