This is a migrated thread and some comments may be shown as answers.

OA Linq and linkage tables

1 Answer 47 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andy
Top achievements
Rank 2
Andy asked on 10 Jun 2011, 01:21 PM
I have 4 tables as follows:

Menu (MenuId, MenuName)

MenuItems (MenuItemId, MenuText, Url)

MenuMenuItem (MenuId, MenuItemId, ParentMenuItemId)

MenuItemRole (MenuId, MenuItemId, RoleId)

When creating the Domain Model the Menu table and MenuItems tables are mapped into classes but the two linkage tables are not. I need to implement the following SQL in Linq.   Any help would be greatly appreciated.

SELECT mi.MenuItemId,mi.Name,mi.Url,mmi.ParentMenuItemId FROM MenuItem as mi
 
    INNER JOIN MenuMenuItem as mmi
    ON mi.MenuItemId = mmi.MenuItemId
     
    INNER JOIN MenuItemRole as mir
    ON mi.MenuItemId = mir.MenuItemId
     
    LEFT OUTER JOIN aspnet_UsersInRoles as uir
    ON mir.RoleId = uir.RoleId 
     
    WHERE mmi.MenuId = @MenuId AND mir.MenuId = @MenuId AND (uir.UserId = @UserId OR mir.RoleId IS NULL)
    ORDER BY mmi.ParentMenuItemId ASC

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 15 Jun 2011, 04:10 PM
Hello Andy,

 The join tables are intentionally not mapped to objects. Instead of them you get a collection on each side. For example in your case you get a collection of menu items in your menu. This collection will be filled with the corresponding menu items for each menu so you will not need to write any joins. You can execute any linq queries against the menu object or its menu items collection.

Greetings,
Petar
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Tags
LINQ (LINQ specific questions)
Asked by
Andy
Top achievements
Rank 2
Answers by
PetarP
Telerik team
Share this question
or