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 7164851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:08:38+00:00 2026-05-28T14:08:38+00:00

I have the following class public class Account { IEnumerable<AccountData> Data { get; set;

  • 0

I have the following class

public class Account
{
    IEnumerable<AccountData> Data { get; set; }
}

where AccountData is

public class AccountData
{
    public virtual long Id { get; set; }
    public virtual AccountTag AccountTag { get; set; }
    public virtual string Value { get; set; }
}

and where Account Tag is

public class AccountTag
{
    public virtual long Id { get; set; }
    public virtual string Name { get; set; }
}

I want to return all accounts where the Data field is in a list of key value pairs . long is the AccountTag.Id, and the AccountData.Value contains the string

Here is what I have so far, but this is performed on the web server and there could be thousands of accounts returned so I am looking for a linq to sql version.

public IEnumerable<Account> FindByCompanyDataTags(long companyId, IEnumerable<KeyValuePair<long, string>> tags)
{
    var tempAccounts = (from acc in this.Data where acc.Company.Id == companyId orderby acc.Name select acc);
    IList<Account> accounts = new List<Account>();

    foreach (var account in tempAccounts)
    {
       var matches = true;
       foreach (var t in tags)
       {
          if (account.Data.Any(x => x.AccountTag.Id == t.Key && x.Value.Contains(t.Value)))
          {
            continue;
          }

          matches = false;
          break;
        }

        if (matches)
        {
          accounts.Add(account);
        }
      }

      return accounts;
}

If I use resharper to convert this into a linq expression I get the following

public IEnumerable<Account> FindByCompanyDataTags(long companyId, IEnumerable<KeyValuePair<long, string>> tags)
{
  var tempAccounts = (from acc in this.Data where acc.Company.Id == companyId orderby acc.Name select acc);
  IList<Account> accounts = (from account in tempAccounts let matches = tags.All(t => account.Data.Any(x => x.AccountTag.Id == t.Key && x.Value.Contains(t.Value))) where matches select account).ToList();

  return accounts;
}

But when I run this I get a method not supported exception.

This is really confusing me, any suggestions?

  • 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-28T14:08:39+00:00Added an answer on May 28, 2026 at 2:08 pm

    That’s happening because in first case you prepare query to db during foreach execution here

    foreach (var account in tempAccounts)
    {....}
    

    You get collection of Account objects and working with them on client side in memory (other words, you’re using Linq to objects)

    In the second case you’re trying execute Linq to Sql query but provider cannot translate working with your KeyValuePair objects into sql query, therefore it raise exception said about that.

    UPDATE

    Try to use IQueryable and build your query thorugh consequently applying Where clause:

    IQueryable<Account> tempAccountsWithWhere = tempAccounts;
    foreach (var tag in tags)
    {
        tempAccountsWithWhere = tempAccountsWithWhere.Where(
            a => a.Data.Any(
                ad => ad.AccountTag.Id == tag.Key && ad.Value.Contains(tag.Value)));
    }
    IList<Account> accounts = tempAccountsWithWhere.ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class public class UIControl { public string FName{ get; set;
I have the following class: public class Account { public int AccountID { get;
I have the following class public class Car { public Name {get; set;} }
I have the following class public class CountrySpecificPIIEntity { public string Country { get;
I have the following class public class CountrySpecificPIIEntity { public string Country { get;
Let just say I have the following data models: public class Account { public
I have a class which has the following fields: public Account account; public IEnumerable<PurchaseTransaction>
I have a following POCO class public class Account { [Key,DatabaseGenerated(DatabaseGenerationOption.Identity)] public string AccountId
I have the following model public class Account { public int Id { get;
I have the following set: public class Account : AuditableTable, IAccount { } public

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.