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

  • SEARCH
  • Home
  • 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 6707779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:40:48+00:00 2026-05-26T07:40:48+00:00

Consider this code: var query = from groupRole in CurrentItem.MEMGroupRoles select groupRole.MEMRole; this.AvailableRoles =

  • 0

Consider this code:

var query = from groupRole in CurrentItem.MEMGroupRoles 
            select groupRole.MEMRole;
this.AvailableRoles = this.allRoles.Except(query.AsEnumerable()).ToList();

In this code I take allRoles except those roles that CurrentItem already have. 2 issues:

  1. It doesn’t work because I compare on objects and those objects are different instances
  2. I don’t like 2 lines and like to improve.

Here is pseudo-code on what I really need to do right now:

var queryIds = from groupRole in CurrentItem.MEMGroupRoles 
               select groupRole.MEMRole.RoleId;
this.AvailableRoles = this.allRoles.Except(where RoleId query.AsEnumerable()).ToList();

How do I write query like this?

EDIT:

explanation:

  1. allRoles contains list of MEMRole objects
  2. CurrentItem.MEMGroupRoles contains list of MEMGroupRole objects and each MEMGroupRole contains MEMRole inside

I want to SELECT all MEMRole objects that’s inside allRoles EXCEPT those MEMRoles that burries inside CurrentItem. First code snippet would work, but I need to compare MEMRole to MEMRole by MEMRole.RoleId since it’s a different instances of the same database 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-26T07:40:48+00:00Added an answer on May 26, 2026 at 7:40 am

    Following the approach you suggested:

    var ids = CurrentItem.MEMGroupRoles.Select(g => g.MMERole.RoleId);
    this.AvailableRoles = this.allRoles.Where(r => ids.All(i => i != r.RoleId));
    

    Alternatively (althought I wouldn’t go that road), if you must have single query, you can append both roles collections (current and all), group them by RoleId and pick groups that only have single member:

    this.AvailableRoles = CurrentItem.MEMGroupRoles
        .Select(g => g.MEMRole)
        .Concat(this.allRoles)
        .GroupBy(r => r.RoleId)
        .Where(g => g.Count() == 1)
        .Select(g => g.First());
    

    This results in roles that weren’t in CurrentItem.MEMGroupRoles collection. But once again, it’s just … for sport 🙂

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

Sidebar

Related Questions

Consider this code: var query = db.Table .Where(t => SomeCondition(t)) .AsEnumerable(); int recordCount =
Consider this code: var files = Directory.GetFiles(filePath); var dataFiles = from file in files
Consider the following code: var Products_First = (from Entities.Product p in myContext.Product select p);
Consider this code: var img = new Image(); img.onload = function() { console.log(this.width); };
Consider this code... $(function() { for (var i = 0; i < 10; i++)
Consider this code: int size = 100 * 1000 * 1000; var emu =
Consider this code (shortened) function getSecret() { db.transaction( function (transaction) { transaction.executeSql( 'SELECT *
Consider this (psuedo-code): var country = new Country(); addChild(country); var state = new State();
Consider this code: static void Main(string[] args) { var persons = new List<Person> {
Consider this code below: <a href="javascript:void(-1)" id="a1">a1</a> <a href="javascript:void(-1)" id="a2">a2</a> <script type="text/javascript"> var buttons

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.