OA Linq and linkage tables

2 posts, 0 answers
  1. Andy
    Andy avatar
    18 posts
    Member since:
    Apr 2011

    Posted 10 Jun 2011 Link to this post

    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
  2. PetarP
    PetarP avatar
    754 posts

    Posted 15 Jun 2011 Link to this post

    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.

    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  3. DevCraft banner
Back to Top