Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6560005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:24:16+00:00 2026-05-25T13:24:16+00:00

Original SQL Query: SELECT e.id, e.[type_id], e.name FROM [user] u JOIN user_group ug ON

  • 0

Original SQL Query:

SELECT e.id, e.[type_id], e.name
FROM [user] u
JOIN user_group ug ON ug.[user_id] = u.id
JOIN usergroup grp on grp.id = ug.group_id
JOIN access_entity ae ON ae.group_id = grp.id
JOIN entity e on e.id = ae.entity_id
WHERE u.id = 184
GROUP BY e.id, e.[type_id], e.name

UNION

SELECT e.id, e.[type_id], e.name
FROM [user] u
JOIN user_group ug ON ug.[user_id] = u.id
JOIN usergroup grp on grp.id = ug.group_id
JOIN CRUD xs on xs.FK_Group_ID = grp.id
JOIN entity_type et on et.id = xs.FK_TypeID
JOIN entity e on e.[type_id] = et.id
WHERE u.id = 184 
AND e.confidential = 0 
AND xs.[Read] = 1
GROUP BY e.id, e.[type_id], e.name

Translated to Linq to Sql:

var A = M.users
    .Join(M.user_groups, u => u.id, ug => ug.user_id, (u, ug) => new { u = u, ug = ug })
    .Join(M.usergroups, x => x.ug.group_id, grp => grp.id, (x, grp) => new { u = x.u, ug = x.ug, grp = grp })
    .Join(M.access_entities, x => x.grp.id, ae => ae.group_id, (x, ae) => new { u = x.u, ug = x.ug, grp = x.grp, ae = ae })
    .Join(M.entities, x => x.ae.entity_id, e => e.id, (x, e) => new { u = x.u, ug = x.ug, grp = x.grp, ae = x.ae, e = e })
    .Where(x => x.u.id == Global.CurrentUser.id);

var B = M.users
    .Join(M.user_groups, u => u.id, ug => ug.user_id, (u, ug) => new { u = u, ug = ug })
    .Join(M.usergroups, x => x.ug.group_id, grp => grp.id, (x, grp) => new { u = x.u, ug = x.ug, grp = grp })
    .Join(M.CRUDs, x => x.grp.id, xs => xs.FK_Group_ID, (x, xs) => new { u = x.u, ug = x.ug, grp = x.grp, xs = xs })
    .Join(M.entity_types, x => x.xs.FK_TypeID, et => et.id, (x, et) => new { u = x.u, ug = x.ug, grp = x.grp, xs = x.xs, et = et })
    .Join(M.entities, x => x.et.id, e => e.type_id, (x, e) => new { u = x.u, ug = x.ug, grp = x.grp, xs = x.xs, e = e })
    .Where(x => x.u.id == Global.CurrentUser.id && x.xs.Read && x.e.confidential == 0);

var RestrictedEntities = A.Select(x => x.e).Union(B.Select(x => x.e));

The problem is that the Entity Framework doesn’t show tables like user_group, etc, since it’s just a 1:* connection table.

In Entity Framework, I can basically do:

IQueryable<IEnumerable<IEnumerable<entity>>> Entities = this.ObjectContext.users.Select(u => u.usergroups.Select(ug => ug.access_entity.Select(ae => ae.entity)));

Is there a way to have that returned as just a

IQueryable<entity>

?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:24:17+00:00Added an answer on May 25, 2026 at 1:24 pm

    Is SelectMany what you are after?

    I believe

    this.ObjectContext.users.SelectMany(
      u => u.usergroups.SelectMany(
        ug => ug.access_entity.Select(ae => ae.entity)));
    

    should have type IEnumerable<entity>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have the following SQL query: SELECT id,name FROM user WHERE id IN
Consider the following SQL Server 2005/2008 query: Select [UID], [DESC] From SomeTable Order By
I have problems with a query in NHibernate. The original SQL query looks like
I'm having difficuly mapping a simple T-SQL query such as this select min(price) as
I have a sql select query that extracts result as: login_count login_type 2000 iPhone
How do you convert a SQL query with nested SELECT statements to a LINQ
The query below: SELECT i_adgroup_id, i_category_id FROM adgroupcategories_br WHERE i_adgroup_id IN ( SELECT i_adgroup_id
I am trying to get this SQL query to grab 1 more thing from
My original query is doing joins using the WHERE clause rather than JOIN. I
Jeff Atwood asked the original question about parameterizing a SQL IN clause , but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.