我的'一對多'Petapoco配方如下。這些文檔對我來說不夠清楚。在Linqpad中創建一個數據庫連接,它會顯示你可以添加到生成的Petapoco poco類的所有導航屬性。在Linqpad中執行相同的SQL,以確保它獲得您期望的數據。
// subclass the generated Parent table pocos, add navigation prop for children
[ResultColumn] public List<DecoratedChild> Child { get; set; }
// subclass the generated Child table pocos, add navigation prop for parent
[ResultColumn] public DecoratedParent Parent { get; set; }
// to get children with parent info
List<DecoratedChild> children = db.Fetch<DecoratedChild, DecoratedParent>(SELECT child.*, parent.* from ...)
// to get children with parent info, using PetapocoRelationExtensions
List<Child> children = db.FetchManyToOne<Child, Parent>(child => child.ID, "select child.*, parent.* from ...
// to get parents with children info, using PetapocoRelationExtensions
List<Parent> parents = db.FetchOneToMany<Parent, Child>(par => par.ID, child => child.ID != int.MinValue, "select parent.*, child.* from ...
SQL選擇順序重要,與獲取類型列表相同!導航道具將會有父母或孩子的數據... 與3個級別的電話將是這樣的:
List<DecoratedGrandChild> grandChildColl = db.Fetch<DecoratedGrandChild, DecoratedChild, DecoratedParent>(SELECT grandch.* , child.*, parent.* from ...)
這不是很好。這是一個駭人的解決方法(爲什麼我不喜歡完整的ORM,因爲你最終會破解代碼以使其工作並使其快速運行(呃))。支持多結果集現在不會太難嗎?這絕對不如自動分離列。 ** Dapper支持多結果集**爲什麼PetaPoco不能做同樣的事情。你不需要平面類,你也可以將更少的數據從數據庫傳輸到中間層。 – 2011-05-21 07:26:19
但你的答案仍然值得+1,因爲這是一個可能的解決方案。 – 2011-05-21 07:28:03