Use Single :
Product product = _productContext.Products .Single(p => p.Name == "BrownShoes");
or
Product product = _productContext.Products .Where(p => p.Name == "BrownShoes") .Single();
There is no syntax for the query expression for Single, so you should call it as a regular extension method. At this point, your request is easier to write in full with a dotted record, therefore, the form above. You could write this as:
Product product = (from p in _productContext.Products where p => p.Name == "BrownShoes" select p).Single();
But it got a lot more fluff. If there are no items as a result, an exception will be thrown.
source share