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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:23:35+00:00 2026-06-04T01:23:35+00:00

Normally I use stored procedures / work in SQL so apologies if I get

  • 0

Normally I use stored procedures / work in SQL so apologies if I get the terminology slightly off here..

I have a database, with 3 seperate tables, and I need to search multiple fields in each of the 3 tables.

Im sure that I am not doing this the mose effective way, initially I am trying to do it in simple seteps to understand it.

I have the following;

    var foo1 = entities.table1.Where(a => a.bodyText.Contains(searchString) || a.pageTitle.Contains(searchString));
    var foo2 = entities.table2.Where(b => b.newsArticle.Contains(searchString) || b.newsArticle.Contains(searchString));
    var foo3 = entities.table3.Where(c => c.ImageDescriptionContains(searchString));

I need to combine all these results into a single repeater for display.

At this point all 3 sets of data are in seperate, unique collections of anonymous data. So whats the best way of converting these into a single coherent bindable source?

I was thinking of itereating through each list in turn, pulling out the fields I need to display and putting them in a new class, then binding a lsit of these classes to the repeater.

But it all seems a bit clunky to me.

Is there a way of doing the search across all 3 tables in one go, and returning just the fields I need from each table, with a common name (i.e. in SQL I could write

    select b.newsArticle as myText, 

or

    select newsArticle, '' 

to return the news article and an empty string).

  • 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-04T01:23:37+00:00Added an answer on June 4, 2026 at 1:23 am

    This would combine:

    var foos = foo1.ToList();
    foos.AddRange(foo2);
    foos.AddRange(foo3);
    

    To get just what you want:

    var myExtractedValues = foos.Select(x => new { 
             Article = !string.IsNullOrEmpty(x.newsArticle)) 
                               ? x.newsArticle 
                               : string.Empty});
    

    I have used an anonymous type here but you could swap the new {} with a type of your own.

    I reverse the operator on the IsNullOrEmpty but that is just a personal preference (I prefer how is reads.)

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

Sidebar

Related Questions

I normally use the following code in SQL Server: IF EXISTS (SELECT * FROM
I normally use a dirty method to get my Facebook Graph API token key
I have identified the query constructs my users normally use. Would it make sense
Normally the parameterized SQL works great for CRUD, but I have one instance where
I'm trying to understand blocks. I get how to use them normally, when passed
Normally, when you want to call a stored procedure directly through Linq to Sql,
We normally use these statements to add anew record to database. MyDataContext.InsertOnSubmit(AnObject); MyDataContext.SubmitChanges(); Other
I normally use fully-explicit transactions in my stored procs (BEGIN TRANSACTION .... COMMIT). I
I'm currently building an application using entity framework. Normally I would use a stored
I normally use gVim for editing, but I sometimes use vim when remotely connecting

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.