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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:00:56+00:00 2026-06-16T04:00:56+00:00

I am trying to merge 2 classes into a third on the date properties,

  • 0

I am trying to merge 2 classes into a third on the date properties, for binding to a graph I have already setup.

public class Last30DaysHours
{
    public DateTime Date { get; set; }
    public float Hours { get; set; }
    public float LostHours { get; set; }
}

public class MachineHours
{
    public DateTime Date { get; set; }
    public float Hours { get; set; }
}

into

public class GraphLast30Days
{
    public DateTime Date { get; set; }
    public float Hours { get; set; }
    public float LostHours { get; set; }
    public float SelectedMachine { get; set; }
}

So far I have this linq statement which almost compiles.
The error with the current statment is “‘x’ does not exist in the current context”.

I know what this means but I don’t know how to make it accessable in the statement.

IEnumerable<GraphLast30Days> last30DaysMachineHoursSelect = _last30DaysMachineHours
            .Select(p => (_last30Days
                            .Where(x => x.Date == p.Date)  <= 
                            (new GraphLast30Days { 
                                                    Date = x.Date, 
                                                    Hours = x.Hours, 
                                                    LostHours = x.LostHours, 
                                                    SelectedMachine = p.Hours 
                                                  })));             

My question is how do I make x accessable by the second half of the statement or what is a better statement to achieve the same results?

Thanks for the help.

  • 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-16T04:00:57+00:00Added an answer on June 16, 2026 at 4:00 am

    You’d wont to use join to join your collections by date (not sure I got the correct proeprties, but you got the idea):

    IEnumerable<GraphLast30Days> last30DaysMachineHoursSelect = 
            from machineHours in _last30DaysMachineHours
            join last30 in _last30Days on machineHours.Date equals last30.Date
            select
            new GraphLast30Days { 
                Date = machineHours.Date, 
                Hours = machineHours.Hours, 
                LostHours = last30.LostHours, 
                SelectedMachine = machineHours.Hours
                };
    

    Or with alternative syntax:

        var result = _last30DaysMachineHours.Join(_last30Days, graph => graph.Date, last30 => last30.Date, 
                                                 (graph, last30) => new GraphLast30Days
                                                                    {
                                                                            Date            = graph.Date,
                                                                            Hours           = graph.Hours,
                                                                            LostHours       = last30.LostHours,
                                                                            SelectedMachine = graph.Hours
                                                                    });
    

    In case you don’t wont to filter out missing values you’ll need to do left join:

    IEnumerable<GraphLast30Days> last30DaysMachineHoursSelect =
        from last30 in _last30Days
        from machineHours in _last30DaysMachineHours.Where (h => h.Date == last30.Date).DefaultIfEmpty()
        select
        new GraphLast30Days { 
            Date = last30.Date, 
            Hours = last30.Hours, 
            LostHours = last30.LostHours, 
            SelectedMachine = machineHours == null ? 0 : machineHours.Hours
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to merge several data.frames into one data.frame . Since I have
I am trying to merge many xml files into one. I have successfully done
So, I am trying to merge two classes, a Bullet Class and a BulletCache
I am trying to merge 2 simple programs I have made to one .jar.
I am trying to merge the data from two tables into one result but
I am trying idiomatically merge multiple maps into a single map using clojure. Input
I've been trying to merge my dev branch into the master branch but as
Trying to merge some data that I have. The input would look like so:
im trying to merge two arrays together. both have numeric keys and are unique.
I am trying to merge some contents from table1 and table2 into another table3

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.