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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:07:45+00:00 2026-05-26T15:07:45+00:00

I have 2 tables that I need to load together all the time, the

  • 0

I have 2 tables that I need to load together all the time, the both must exist together in the database. However I am wondering why Linq to Sql demands that I have to load in a collection and then do a join, I only want to join 2 single tables where a record where paramid say = 5, example…

var data = _repo.All<TheData>(); //why do I need a collection/IQueryable like this?

var _workflow = _repo.All<WorkFlow>()
                .Where(x => x.WFID== paramid)
                .Join(data, x => x.ID, y => y.WFID, (x, y) => new
                {
                    data = x,
                    workflow = y
                });

I gues then I need to do a SingleOrDefault()? If the record is not null pass it back?

I Understand the Sql query comes out correctly, is there a better way to write this?

NOTE: I need to search a table called Participants to see if the loggedonuser can actually view this record, so I guess I should leave it as this? (this is main requirement)

var participant = _repo.All<Participants>();

.Any(x=> x.ParticipantID == loggedonuser.ID); //add this to above query...
  • 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-26T15:07:46+00:00Added an answer on May 26, 2026 at 3:07 pm

    The line var data = _repo.All<TheData>(); is something like saying ‘start building query against the TheData table’.
    This function returns you an IQueryable which will contain a definition of the query against your database.

    So this doesn’t mean you load the whole TheData table data with this line!

    The query will be executed the moment you do something like .Count(), .Any(), First(), Single(), or ToList(). This is called deferred execution.

    If you would end your query with SingleOrDefault() this will create a sql query that joins the two tables, add the filter and select the top most record or null(or throw an error if there are more!).

    You could also use Linq instead of query extension methods.
    It would look like:

    var data = _repo.All<TheData>(); 
    
    var _workflow = from w in _repo.All<WorkFlow>()
                    join t in _repo.All<TheData> on  w.Id equals t.WFID
                    where x.WIFD = paramid
                    select new
                    {
                        data = t,
                        workflow = x
                    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database two tables and a linking table that I need a
I have multiple tables that need to be merged into one. SELECT name, SUM(money)
I have a couple of tables that need to be be joined. The tables
I have 2 tables in a DB with very similar schemas that need to
I have a two tables that are Subject and chapter . I need to
Need help with a query that I wrote: I have three tables Company id
I have two tables described below. What I need is a single query that
I have a table that I need to update where all columns are optionally
I have a large database table that I need to display on a Windows
So I have a boat load of pivot tables that I upload everyday to

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.