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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:55:20+00:00 2026-06-18T23:55:20+00:00

I have the following entities: [Table(Entities)] public abstract class Entity { public int EntityID

  • 0

I have the following entities:

[Table("Entities")]
public abstract class Entity { 
 public int EntityID { get; set; } 
 public string Description { get; set; }
 public virtual ICollection<Tag> Tags { get; set; }
}

And the Tag Entity:

public class Tag {
    public int TagID { get; set; }
    public int EntityID { get; set; }
    public string TagValue { get; set; }
}

As the above makes sort of clear Tags are not reused just stored as strings. This has made determining whether Entities share tags slightly more difficult (and slow).

I have a working search to return a list of entities in which the entities contain any of the tags:

List<string> searchTags = new List<String> {"test1", "test2"};
entities = (_entityRepository.Entities
            .Where(o=>o.Tags.Any(f=>searchTags.Contains(f.TagValue)));

Now I also need to return a list of Entities which contain all of the tags in the list. As a non-property variable cannot be passed into a Contains method I cannot just reverse the order of the call with an all, but this is basically what I am trying to achieve:

entities = (_entityRepository.Entities
            .Where(o=>o.Tags.All(f=>f.TagValue.Contains(searchTags)));

I think I have just hit the point where I need to correct the DB schema to re-use Tags which should provide a general performance benefit when filtering my entities on lists of Tags, but I still wanted to ask the following questions:

  1. Am I over complicating this and is there a simple Linq statement which accomplishes this or,
  2. Is this something for which I would should use predicate builder to set my criteria?
  • 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-06-18T23:55:22+00:00Added an answer on June 18, 2026 at 11:55 pm

    This can be done like this:

    var query = _entityRepository.Entities.Select(e => e);
    query = searchTags.Aggregate(query, (current, tag) => current.Where(e => e.Tags.Any(t => t.TagValue == tag)));
    var result = query.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 entities public abstract class Card { public virtual int Id
I have following entities: public class Product { [Key] public int Id{get;set;} //other properties
I have the following (simplified) Hibernate entities: @Entity @Table(name = package) public class Package
I have the following entities: TEAM @Entity @Table public class Team { [..] private
Suppose we have the following entities: public class plaserv { public virtual int id
I have the following entities in Entity Framework: public class School { public int
I have the following JPA (2.0.2) entities: Employee @Entity @Table(name = T_EMPLOYEE) public class
I have the following two entities: Person.java: @Entity @Table(name=PERSON) public class Person { @Id
Suppose I have the following entities: @Entity @Table(name = A) public class A implements
I have the 2 following entities: @Entity @Table(name = brand) public class Brand {

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.