मैं ग्राहक जानकारी प्रदर्शित करना चाहता हूं। फिर मैंने कुछ कक्षाएं बनाई; ग्राहक, वितरण, आदेश, ऑर्डरलाइन, उत्पाद, और किराये पर डीबी। किराये पर डीबी कक्षा उत्पाद, ग्राहक, आदेश, ऑर्डरलाइन, और वितरण के 5 डीबीसेट सेट करता है। जब मैं सूची दृश्य के साथ UserController बनाने के लिए, मैं ग्राहकों की जानकारी प्रदर्शित नहीं कर सकता है, और यह त्रुटियों लेता है:एएसपी.नेट एमवीसी 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; }
}
}
यह मेरे लिए एक विशेष मामले में काम किया। मैंने मॉडल के लिए कोड लिखने के बाद एक नियंत्रक जोड़ा, और त्रुटि नहीं मिली। उस समय मुझे एहसास हुआ कि मॉडल वह नहीं था जो मैं चाहता था कि सभी जेनरेट किए गए विचार बहुत गलत थे इसलिए मैंने नियंत्रक/विचार हटा दिए। फिर जब मैंने मॉडल को ठीक किया और नियंत्रक जोड़ा तो त्रुटि दिखाई दी। एक घंटे के लिए घूमने के बाद मैंने [कुंजी] जोड़ा और यह काम किया। शायद दृश्य स्टूडियो एमवीसी अजीबता या कैश, पता नहीं ... – isitdanny