Reputation: 5312
I want to get the first element of the LinqToEntities request.
Here is my code:
var para = (from param in context.Parameters
where param.Code == paramCode
select param.ValueDecimal);
Does anyone know how to do that?
Thanks
**Edit:**
Thanks for your responses. It works.
Upvotes: 2
Views: 76
Reputation: 498904
Use the First
or FirstOrDefault
methods:
var para = (from param in context.Parameters
where param.Code == paramCode
select param.ValueDecimal).First();
First
will throw an exception if the Enumerable
is empty.
var para = (from param in context.Parameters
where param.Code == paramCode
select param.ValueDecimal).FirstOrDefault();
Upvotes: 4
Reputation: 8521
FirstOrDefault
returns the first element in the list or null
if the list has no elements.
var para = (from param in context.Parameters
where param.Code == paramCode
select param.ValueDecimal).FirstOrDefault();
Upvotes: 4