I am fetching data from the database using entity framework and linq queries. I am wondering about the performance of getting data.
Here is my code. I just want to check that a Well exists in database or not. Database table has 15 columns and 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 performance is better?