Chcę wyświetlać informacje o kliencie. Potem stworzyłem klasy; Klient, dostawa, zamówienie, zamówienie zamówienia, produkt i wynajemDB. wypożyczanie zestawów klasy DB 5 DbSet produktu, klienta, zamówienia, zamówienia zamówienia i dostawy. Kiedy robię UserController z widoku listy, nie może wyświetlić informacje o klientach, a to trwa błędy:ASP.NET MVC 3 EntityType nie ma zdefiniowanego klucza
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.
nie wiem dlaczego te podmioty wymaga klucza? Nie mam pojęcia o tym błędzie .. Czy możesz mi pomóc?
--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 w modelach 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 w modelach folder--
namespace MvcApplication2.Models
{
public class OrderLine
{
public int basketId { get; set; }
public int productId { get; set; }
public int quantity { get; set; }
}
}
To zadziałało dla mnie w specjalnym przypadku. Dodałem kontroler po napisaniu kodu dla modelu i nie dostałem błędu. W tym momencie zdałem sobie sprawę, że model nie jest tym, co chciałem oznaczać, że wszystkie wygenerowane widoki były bardzo błędne, dlatego usunąłem kontroler/widoki. Następnie, kiedy naprawiłem model i dodałem sterownik, pojawił się błąd. Po spędzeniu z nim czasu przez godzinę dodałem klawisz [Key] i zadziałało. Może wizualne studio Mvc dziwactwa lub pamięci podręcznej, nie wiem ... – isitdanny