سلام
دوتا کلاس زیر را داریم
public class City { public City() { } public int CityId { get; set; } public string Name { get; set; } public int CityTypeId { get; set; } [ForeignKey(nameof(CityTypeId))] public virtual CityType CityType { get; set; } public int ParentId { get; set; } } public class CityType { public CityType() { } public int CityTypeId { get; set; } public string Name { get; set; } public virtual ICollection<City> Cities { get; set; } }
که
public int ParentId { get; set; }
که id خود جدول می باشد
چگونه می توانم تعریف کنم که ارجاع از خود id همین جدول است
برنامه در mvccore است
لینک زیر را مشاهده کنید :
c# - Map category parent id self referencing table structure to EF Core entity
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)