Erw*_*in1 0 ado.net entity-framework entity-framework-4
我的ADO.Net实体数据模型下面有一个名为ABC的模型(以自引用表为模型).
ABC Properties are
----------
ParentID
Child ID
ABC Navigation Properties are
----------
ParentCategory (refers to the parent category or the 0..1 side of the relationship)
SubCategories (refers to the children or the * side of the relationship, represents the navigation property for the children)
Run Code Online (Sandbox Code Playgroud)
我想为特定的ParentID(即不是层次结构的顶部)选择子孙.我怎样才能做到这一点.有人可以提出一个例子.谢谢
我在vb中尝试了下面提出的解决方案,但它只加载了一个级别;
我在VB中这样做,所以向C#程序员道歉.
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Dim ctx = New links2Entities
Dim query = From c In ctx.PBS.Include("SubCategory.SubCategory") Where (c.Parent_ID = 7)
For Each result As PB In query
Debug.WriteLine("ID: {0}", result.Child_ID)
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
如果您需要按其Id选择实体并急切加载其子级的两个级别,则需要执行以下操作:
var query = context.ABC.Include("SubCategories.SubCategories")
.Where(e => e.Id == id);
Run Code Online (Sandbox Code Playgroud)
在EF 4.1的情况下,它应该是:
var query = context.ABS.Include(e => e.SubCategories.Select(s => s.SubCategories))
.Where(e => e.Id == id);
Run Code Online (Sandbox Code Playgroud)
如果您需要在任何深度上急切加载所有子类别,则无法告诉它EF.
| 归档时间: |
|
| 查看次数: |
577 次 |
| 最近记录: |