Find() vs. Where().FirstOrDefault()

前端 未结 7 1877
南旧
南旧 2020-11-27 11:31

I often see people using Where.FirstOrDefault() to do a search and grab the first element. Why not just use Find()? Is there an advantage to the ot

7条回答
  •  再見小時候
    2020-11-27 12:31

    There is a very important difference if the source of the data is Entity Framework: Find will find entities in the 'added' state that are not yet persisted, but Where will not. This is by design.

提交回复
热议问题