मेरे मॉडल:एफई-संहिता एक नौवहन संपत्ति के साथ पहले जटिल प्रकार
public class Country
{
public int CountryId { get; set; }
public string Name { get; set; }
public virtual ICollection<User> Users { get; set; }
}
public class Location
{
public string Address { get; set; }
public virtual int CountryId { get; set; }
public virtual Country Country { get; set; }
}
public class User{
protected User()
{
Location = new Location();
}
public int UserId { get; set; }
public Location Location { get; set; }
}
जब डेटाबेस पैदा करने, मैं मिलता है:
One or more validation errors were detected during model generation:
System.Data.Edm.EdmEntityType: : EntityType 'Location' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Locations� is based on type �Location� that has no keys defined.
मैं एक जटिल प्रकार के अंदर एक नौवहन संपत्ति कैसे है? अगर मैं देश नेविगेशन संपत्ति को हटा देता हूं, तो यह ठीक काम करता है।
लेकिन 'स्थान' कक्षा के अंदर 'CountryID' पूर्णांक के बारे में क्या? क्या यह एक विदेशी कुंजी बाधा बनाना संभव है? (मुझे एक ही समस्या है और इसे काम पर नहीं मिल सकती है) –
@ इसाक: नहीं, यह संभव नहीं है। यदि आप इसे डेटाबेस में एफके रखना चाहते हैं तो आपको इसे डेटाबेस में सीधे करना होगा लेकिन ईएफ इसे प्रतिबिंबित नहीं करेगा। –
तथ्य यह है कि यह समर्थित नहीं है सीधे एमएसडीएन पर कॉम्प्लेक्स प्रकार के विवरण में उल्लिखित है: http://msdn.microsoft.com/en-us/library/bb738472.aspx –