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

  • Home
  • SEARCH
  • 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 6096447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:55:41+00:00 2026-05-23T12:55:41+00:00

var grid = new System.Web.UI.WebControls.GridView(); grid.DataSource = from booking in bookings join f in

  • 0
var grid = new System.Web.UI.WebControls.GridView();
        grid.DataSource = from booking in bookings
                         join f in getallAttendees on booking.UserID equals f.UserID into fg
                         from fgi in fg.DefaultIfEmpty() //Where(f => f.EventID == booking.EventID)
                          where
                              booking.EventID == id

                          select new
                          {
                              EventID = booking.EventID,
                               UserID = booking.UserID,
                              TrackName = booking.Name,
                              BookingStatus = booking.StatusID,
                               AttendeeName = booking.FirstName,
                             // name = account.FirstName,
                              AmountPaid = booking.Cost,
                              AttendeeAddress = booking.DeliveryAdd1,
                              City = booking.DeliveryCity,
                               Postcode = booking.Postcode,
                              Date = booking.DateAdded,
                              product = fgi == null ? null : fgi.productPurchased
                         };

Booking table design:

ID, EventID, UserID, BookingStatus, AmountPaid, AttendeeAddress, City, Date

Product table design:

ID, EventID, SecondDriver, Apples, Bananas, SecondItem

The association between booking and product table is many to many and the foreign key is UserID

The above Linq-to-SQL query returns the data of only users whose booking.UserID equals att.UserID, what I want is to return all the users of that particular event also with apples and banana fields if they have bought else fill null in that columns.

Any possible solutions or examples will be highly appreciated.

  • 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-23T12:55:42+00:00Added an answer on May 23, 2026 at 12:55 pm

    I think you are looking for an equivalent to a Left Join. You can accomplish this by using the DefaultIfEmpty() extension method. Modify your join statement and add another from in like so:

    join at in getallAttendees on booking.UserID equals at.UserID into attg
    from att in attg
    

    In your select statement you can use the ternary operator ? : like so:

    SecondItem = att == null ? null : att.SecondItem,
    

    Edit

    Your bookings and getallAttendees IQueryable need to come from the same context if you want to join them together.

    Otherwise you will need to use getallAttendees.ToList() and bookings.ToList()

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

Sidebar

Related Questions

This query works great: var pageObject = (from op in db.ObjectPermissions join pg in
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
var insInvoice = new NpgsqlCommand( @INSERT INTO invoice_detail( invoice_id, invoice_detail_id, product_id, qty, price, amount)
var newUser = new tblUser() { Email = strEmail, Password = strPassword, DateBirth =
I'm trying to bind columns from two different tables in to gridview using Linq
var i : integer; i := 1234567; Given the above, I want the string
var foo = { someKey: someValue }; var bar = someKey; How do I
Consider: var something = { wtf: null, omg: null }; My JavaScript knowledge is
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Is there an NSIS var to get the path of the currently running installer?

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.