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

前端 未结 7 1887
南旧
南旧 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:19

    Wow i just watch the EF tutorial from MicrosofToolbox today on Youtube. He did say about using Find() and FirstOrDefault(condition) in query and Find() will search for the data you had performed something on that object( add or edit or delete - but not yet saved into the database ) meanwhile FirstOrDefault will only look for what already have been saved

提交回复
热议问题