Home > DeveloperSection > Forums > How do I get a single row from a linq expression in C#?
Norman Reedus
Norman Reedus

Total Post:45

Points:315
Posted on    February-17-2015 6:16 AM

 C# C#  LINQ 
Ratings:


 1 Reply(s)
 521  View(s)
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?



Kamlakar Singh
Kamlakar Singh

Total Post:28

Points:196
Posted on    February-17-2015 6:22 AM

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


Don't want to miss updates? Please click the below button!

Follow MindStick