0

Which is the better way to carry out this search:

context.Parameters.FirstOrDefault(x => x.ParameterName == "SomeValue").ParameterValue

or

context.Parameters.Where(x => x.ParameterName == "SomeValue").FirstOrDefault().ParameterValue

Does it matter at all?

mjwills
  • 23,389
  • 6
  • 40
  • 63
dstewart101
  • 1,084
  • 1
  • 16
  • 38
  • 2
    There is no difference. Be careful with `FirstOrDefault().ParameterValue`, if you get `null` you will get an exception when trying to access `ParameterValue`. – Felipe Oriani Nov 04 '19 at 11:49
  • I'd say that they compile to the very same SQL – Teejay Nov 04 '19 at 11:49
  • 1
    Its a duplicate question you might find the answer [Here](https://stackoverflow.com/questions/8059285/c-sharp-linq-whereexpression-firstordefault-vs-firstordefaultexpression) – Mukul Keshari Nov 04 '19 at 11:52

0 Answers0