HOW DO I GET A SINGLE ROW FROM A LINQ EXPRESSION IN C#?

Norman Reedus

Total Post:45

Points:315
Posted by  Norman Reedus
C#  LINQ 
C#
 839  View(s)
Ratings:
Rate this:

This code is supposed to get a DateTime from a linq expression.

DateTime orderDate = (from order in db.Orders where order.Id == orderRules.OrderId select order.DatumTijd).SingleOrDefault();
Instead I get this errorMessage:
'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

What could be wrong?

  1. Mark M

    Post:28

    Points:196
    Re: How do I get a single row from a linq expression in C#?

    DateTime? orderDate = (from order in db.Orders where order.Id == orderRules.OrderId select order.DatumTijd).FirstOrDefault();

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!