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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:12:37+00:00 2026-05-22T23:12:37+00:00

i have a trouble to write a query with Linq i explain better my

  • 0

i have a trouble to write a query with Linq i explain better my case, i have a database with 2 tables as follow :

it is the first table ;

  • Hotel

  • HotelID (Nvarchar(10) – PK)

  • HotelName (Nvarchar (200))

and this one is the second table ;

  • Period

  • PeriodID (Int (inc) – PK)

  • _From (Datetime )
  • _To (Datetime)
  • HotelID(Nvarchar(10) – FK)

then in the second Table (Period) there is the FK (HotelID) to connect the 2 tables;
Happen sometime i have a HotelName that gets more periods(PeriodID) so my purpose is to show the data in an only one Row into a DataGrid, i show you an example as i want show the data in my DataGrid if there are more periods in the same HotelName:

| HotelName | From | To | From(2) | To(2) | From(3) | To(3) | From(4)| To(4) |


| Excelsior |12/5/10 |3/6/10 | 2/8/10 | 9/9/10 | 23/9/10 | 1/10/10| 2/11/11| 1/12/10|

so i ask do you have any idea/suggest about how to show the data in a DataGrid inside one Row using Linq To Sql ?

thanks so much for your attention .

Have a good time .

Cheers

  • 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-22T23:12:37+00:00Added an answer on May 22, 2026 at 11:12 pm

    This article explains working with hierarchical data binding: http://msdn.microsoft.com/en-us/library/aa478959.aspx

    Then, create an object model which roughly maps to your database tables:

    Hotel
     - ID
     - Name
     - Bookings
      - Booking 1 { From, To }
      - Booking 2 { From, To }
      - Booking n { From, To }
    

    Your Linq should look something like this:

    var hotels = _db.Hotel.Select();
    
    foreach(var hotel in hotels)
        hotel.Bookings = _db.Period.Where(x => x.HotelId == hotel.HotelId).Select();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to LINQ, and I have trouble with a query I'm trying to
I am having some trouble with a linq query I am trying to write.
I am having trouble writing a query. Lets say I have a table full
I have trouble defining a trigger for a MySQL database. I want to change
I have an example database, it contains tables for Movies, People and Credits. The
I'm having trouble writing a query. I have a support tabled called 'MYTABLE' and
I'm having trouble wrapping my head around how to write this query. A hypothetical
I'm learning SQL and I'm having trouble with a query. I have the following
I'm trying to write my first iPhone app and i'm having some trouble with
I'm having trouble finding a way to write a query that will return all

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.