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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:43:57+00:00 2026-06-17T23:43:57+00:00

I have a code table: public class Code { [Key] public int CodeID {

  • 0

I have a code table:

public class Code
{
    [Key]
    public int CodeID { get; set; }

    [Required]
    [StringLength(30)]
    public string Title { get; set; }

    [Required]
    [StringLength(150)]
    public string Description { get; set; }

    public DateTime DateAdded { get; set; }

    public DateTime LastUpdated { get; set; }

    [Required]
    [StringLength(30)]
    public string Project { get; set; }

    [Required]
    [StringLength(30)]
    public string CMS { get; set; }

    public int DotNetVersion { get; set; }

    [Required]
    [StringLength(150)]
    public string Dependencies { get; set; }

    [StringLength(30)]
    public string Author { get; set; }

    public string CodeFile { get; set; }

    [Required]
    [StringLength(100)]
    public string TFSLocation { get; set; }

    ////Creates a relationship in the DB with Tag
    //[ForeignKey("TagID")]
    public virtual ICollection<Tag> Tags { get; set; }

    ////Purely for API
    //[Required]
    public int TagID { get; set; }
}

A tag table:

public class Tag
{
    [Key]
    public int TagID { get; set; }

    [Required]
    [StringLength(30)]
    public string TagName { get; set; }

    ////Creates a relationship in the DB with Code
    public virtual ICollection<Code> Code { get; set; }
}

And a view model:

public class CodeTagViewModel
{
    public List<Tag> Tags { get; set; }
    public List<Tag> SelectedTags { get; set; }        

    public int CodeID { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public DateTime DateAdded { get; set; }
    public DateTime LastUpdated { get; set; }
    public string Project { get; set; }
    public string CMS { get; set; }
    public int DotNetVersion { get; set; }
    public string Dependencies { get; set; }
    public string Author { get; set; }
    public string CodeFile { get; set; }
    public string TFSLocation { get; set; }

}

And I’m trying to run a query to get code files that are linked to tag names that have been searched. At the moment I have something like this:

        List<CodeTagViewModel> models = new List<CodeTagViewModel>();
        List<Code> codes = db.Code.ToList<Code>();

        foreach (Code code in codes)
        {
            models.Add(MapCodeToModel(code));
        }

        var orderedModels = models.ToList();

        if (!String.IsNullOrEmpty(searchString))
        {
            orderedModels = models.Where(x => x.Title.ToUpper().Contains(searchString.ToUpper()) || x.Description.ToUpper().Contains(searchString.ToUpper()) || x.Project.ToUpper().Contains(searchString.ToUpper()) || x.CMS.ToUpper().Contains(searchString.ToUpper()) || x.Dependencies.ToUpper().Contains(searchString.ToUpper()) || x.Author.ToUpper().Contains(searchString.ToUpper())).ToList();

            if(orderedModels.Count == 0)
            {
                var Tags = db.Tags;
                 orderedModels = models.SelectMany(x => x.SelectedTags).Select(t => t).Where(t => t.TagName).Contains(searchString).ToList();
            }
        }

        return View(orderedModels);

Searching based on the other columns of the code table work fine, I just included them so you could get a better idea of what I am trying to do; maybe there is a better way than doing my if statement to see if the search has matched anything else first. It’s just searching on Tags that doesn’t seem to be working for me.

The part I need help with:

 orderedModels = models.SelectMany(x => x.SelectedTags).Select(t => t).Where(t => t.TagName).Contains(searchString).ToList();
  • 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-17T23:43:59+00:00Added an answer on June 17, 2026 at 11:43 pm

    Solved it:

    if(orderedModels.Count == 0)
                {
                    var codesByTag = db.Code.Where(c => c.Tags.Any(t => t.TagName.ToUpper().Contains(searchString))).ToList<Code>();
                    foreach (var searchResult in codesByTag)
                    {
                        orderedModels.Add(MapCodeToModel(searchResult));
                    }
                }
    

    MapCodeToModel is my own self explanatory method that I can post on request if it will help.

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

Sidebar

Related Questions

I have this piece of code: @Entity @Table(name = MOVERS) public class MOVers implements
I'm using EF 4.3.1 Code First Migrations. I have a table like: public class
I have this class hierarchy in code: [Table(A)] public class A : IIdentification {
I have these classes: public class Product { [Key] public virtual int ProductId {
I have code: <display:table name=sessionScope.allUserslist id=userList export=false pagesize=1> <display:column title=Select style=width: 90px;> <input type=checkbox
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
I have a code first application which defined like this: public abstract class Entity
I have the following code (I simplified it & removed unrelevant parts) public class
I have code-first based context with following entities: public class City : IEquatable<City> {
I have the following code snippet. public class ImageStoreActivity extends ListActivity { private DBHelper

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.