I am fetching data from the database using Entity Framework and Linq queries. I am wondering about the performance of getting data. I just want to check whether or not a well
exists in the database. The database table has 15 columns and the number of rows are unknown.
internal static bool WellExists(string name, DatabaseContext context)
{
var name = context.Wells.Where(w => w.name == name).Select(w => w.name).FirstOrDefault();
return !string.IsNullOrEmpty(databaseUwi);
}
Here my point of concern is the line in which I am using Linq queries. In this I am using a Where
, then Select
and then FirstOrDefault
. Another solution is using FirstOrDefault
only.
var well = context.Wells.FirstOrDefault(w => w.name == name);
return !(well == null);
The first query will get only selected data (Select
) which is not required. Which solution's performance is better?