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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:33:50+00:00 2026-06-04T10:33:50+00:00

My ASP.NET MVC project has some chapter class and related tag class They have

  • 0

My ASP.NET MVC project has some

chapter class

and related

tag class

They have many to many relationship though one tag has multiple chapter and also one chapter has multiple tags on it.

My question is: I want to make a query by using tag.title within this structure but LINQ doesn’t allow objects; it only gets variables like string, int …etc.

I am feeling a little bit stupid but I can’t figured it out this basic thing 🙁 (May be I have to give a break to let it be clear in my mind)

My models are:

public partial class Chapter
{
    public string Id { get; set; }
    public string Subject { get; set; }
    public string Content { get; set; }
    public virtual ICollection<Tag> Tags { get; set; }
}

public partial class Tag
{
    public int? TagId { get; set; }
    public string Title { get; set; }
    public int CallCount { get; set; }
    public virtual ICollection<Chapter> Chapters { get; set; }
}

and also for db:

public class DataContext : DbContext
{
    public DbSet<Chapter> Chapters { get; set; }
    public DbSet<Tag> Tags { get; set; }
}

so here we go:

var tag = (from t in db.Tags where t.Title.Contains(search_word)).FirstOrDefault();
var chapters = (from c in db.Chapters where (m.Title.Contains(search_word) || m.Tags.Contains(tag)) select c).ToList();

As I explained above; it gives

“you should use string, guid, int… on queries”

error for this query. I think there is a logical failure I made but my brain stopped responding…

Briefly; I want to search by tag names and if you have another approach I will be pleased to listen it..

Any help will be highly appreciated.

Thanks!

  • 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-04T10:33:51+00:00Added an answer on June 4, 2026 at 10:33 am

    You want:

    var tag = (from t in db.Tags 
               where t.Title.Contains(search_word)
               select t).FirstOrDefault();
    var chapters = (from c in db.Chapters 
                    where m.Title.Contains(search_word) 
                        || m.Tags.Any(t => t.TagId == tag.TagId)
                    select c).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net MVC app that also has a silverlight project for some
I have a ASP.NET MVC project that has a static class in it to
I have a master page in my asp.net MVC project, which has code like
I have a form in an ASP.NET MVC project which has a select drop
My team has a new Asp.net MVC intranet app. I have been doing some
Once an asp.net MVC project has a web deployment project associated with it, there
The ASP.NET MVC 1.0 (final) project template has basic membership built in, but I
In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated
I have a new asp.net mvc project and i am trying to figure out
I have an ASP.NET MVC project with xVal and data annotations and I need

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.