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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:36:27+00:00 2026-06-17T16:36:27+00:00

I am on framework 4.0. This is a WPF application, on sql server CE,

  • 0

I am on framework 4.0. This is a WPF application, on sql server CE, which is a little limiting.
I have an entity that looks like this:

    public class TimeEvent
    {
       public int Id
       {get; set;}
       public DateTime EventDate
       {get; set;}
       public bool CheckIn
       {get; set;}
    }

I have two types of events, one for checkin (CheckIn is true) and one for checkout (CheckIn is false). Each of the events happens once per day.
What I want to do using linq to entities, is to end up with a set of objects like this:

public class Diff
{
   public DateTime Date //The date of both events
   {get; set;}
   public DateTime CheckInTime //Time of first event
   {get; set;}
   public DateTime CheckOutTime //Time of second event
   {get; set;}
   public int Hours //Difference in hours.
   { get { return (CheckOutTime - CheckInTime).Hours;} 
}

There are validation rules in place so no more than one event of each type can happen in one day.
I tried using the aggregate function, but I’m really not getting anywhere.
Thank you!

  • 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-17T16:36:28+00:00Added an answer on June 17, 2026 at 4:36 pm

    Group your time events by EventDate date part. To get that you need to use EntityFunctions.TruncateTime method (simple EventDate.Date will not work with Entity Framework).

    var query = from t in db.TimeEvents
                group t by EntityFunctions.TruncateTime(t.EventDate) into g
                let checkIn = g.Min(x => x.EventDate)
                let checkOut = g.Max(x => x.EventDate)           
                select new Diff {
                    Date = g.Key,
                    CheckInTime = checkIn,
                    CheckOutTime = checkOut                    
                };
    

    Also you can calculate time difference on server side with EntityFunctions.DiffHours(checkOut, checkIn).

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

Sidebar

Related Questions

I develop desktop-based WPF-application, that uses SQL Server 2008 R2 Database and ADO.NET Entity
I have a WPF application in which I use entity framework with mysql connector/net
I have a WPF application in which I'm trying to use Entity Framework 4.1
I'm developing a WPF application using Entity Framework 4 and SQL Server CE database
My application is a WPF C# database app that work with sql Server 2008
We have a WCF service that uses Entity Framework to query a SQL database.
I am using Entity Framework and SQL CE 4.0 with my WPF application. How
This is odd. I have a WPF application that works just fine in XP
I'm building a .NET 4 WPF application using Entity Framework code first and SQL
I have a WPF application developed against the MVVM framework in which the ViewModel

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.