Guest User

Untitled

a guest
Aug 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. VB.NET Linq to Entities Query with child objects
  2. Dim ctx As New AdminCoreEntities
  3. Dim roles = (From r In ctx.Roles where r.Name.StartsWith("cust") Select r) 'list of System.Linq.IQueryable(Of AdminCoreModel.Role)
  4.  
  5. Dim items = From i In ctx.QuickLinks.Include("Roles")
  6. Where (i.TenantID = "470556ba-3574-4b01-a619-b85e9721b966" AndAlso i.Roles.Contains(roles))
  7. Select New With {
  8. i.ID,
  9. i.Name,
  10. .Roles = (From r In i.Roles Select New With {.Id = r.ID, .Name = r.Name})
  11. }
  12.  
  13. Dim ctx As New AdminCoreEntities
  14. Dim items = From i In ctx.QuickLinks ' You don't need Include because you're projecting.
  15. Where (i.TenantID = "470556ba-3574-4b01-a619-b85e9721b966"
  16. AndAlso i.Roles.Any(Function(role) role.Name.StartsWith("cust"))
  17. Select New With {
  18. i.ID,
  19. i.Name,
  20. .Roles = (From r In i.Roles Select New With {.Id = r.ID, .Name = r.Name})
  21. }
Add Comment
Please, Sign In to add comment