我有一個鏈接表,並且一些鏈接將是子鏈接,引用父鏈接ID 但是我無法繞過服務棧ormlite和填充子項的屬性,將在獲得所有鏈接列表時的所有子鏈接。服務棧ormlite和外鍵到同一張表
這裏是我的模型:
public partial class Navigation
{
[Alias("Id"), AutoIncrement]
public int Id { get; set; }
[Alias("ParentId")]
[Display(Name = "ParentId")]
[References(typeof(Navigation))]
public int? ParentId { get; set; }
[Alias("LinkText")]
[StringLength(50, ErrorMessage = " Must be no more than 50 characters long!")]
[Display(Name = "LinkText")]
public string LinkText { get; set; }
[Alias("Action")]
[StringLength(50, ErrorMessage = " Must be no more than 50 characters long!")]
[Display(Name = "Action")]
public string Action { get; set; }
[Alias("Controller")]
[StringLength(50, ErrorMessage = " Must be no more than 50 characters long!")]
[Display(Name = "Controller")]
public string Controller { get; set; }
[Alias("Area")]
[StringLength(50, ErrorMessage = " Must be no more than 50 characters long!")]
[Display(Name = "Area")]
public string Area { get; set; }
[Alias("Visible")]
[Display(Name = "Visible"),Required(ErrorMessage = " is required")]
public bool Visible { get; set; }
[Alias("Sequence")]
[Display(Name = "Sequence")]
public int? Sequence { get; set; }
[ForeignKey(typeof(Navigation))]
public virtual ICollection<Navigation> Children { get; set; }
}
什麼想法?
是有一個快速的方法,我可以做到這一點,例如,創建我的最終結果模型並具有再填充,因爲我需要它,上面的是現有項目的相當大一部分,它使用實體框架在這一刻,我試圖證明,ormlite將能夠處理這樣的事情,在項目中沒有太大的麻煩,不真正理解你發給我的鏈接真的,我不想插入,只是提供結果。謝謝 – davethecoder
我沒有時間自己做這些,但是你可以做一個擴展方法,其行爲與你想要的相似,例如, 'model.Children()'使用反射來查看src +子表並使用約定來構建相應的sql想要的。 –
mythz