I am having problems returning a single object from a Dapper query. I have a simple query and I want to get the first object from the returned collection. What am I missing?
using (SqlConnection sqlConnection = new SqlConnection(GetConnectionString()))
{
string query = @"select * from order";
sqlConnection.Open();
// Works
var orders = sqlConnection.Query<OrderModel>(query);
// Does Not Work ERROR: "does not contain a definition for 'FirstOrDefault' and
// no extension method 'FirstOrDefault'
// accepting a first argument of type 'System.Collections.Generic.IEnumerable<OrderModel>'"
var order = sqlConnection.Query<OrderModel>(query).FirstOrDefault();
}
You are getting this error because you have not added the namespace
using System.Linq
in your cs file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With