DateTime difference in Entity Framework Core

entity-framework-core

Question

Regarding Entity Framework Core, I have the following inquiry:

public class Question {
  public DateTime? Approved { get; set; }
  public DateTime Created { get; set; }
}

public class QuestionModel {
  public TimeSpan ResponseTime { get; set; }
}

List<Question> questions = await context.Questions
  .Select(x =>
    new QuestionModel {
      ResponseTime = x.Approved.Value - x.Created
    }).ToListAsync();

But I encounter the following issue:

System.Data.SqlClient.SqlException: Operand data type datetime2 is invalid for subtract operator.

How can I use Entity Framework Core to get a DateTime difference?

1
1
10/14/2016 6:00:18 PM

Popular Answer

ZZZ_tmp
4
12/5/2016 1:33:36 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow