`from..where` or `FirstOrDefault` in LINQ

前端 未结 3 1574
滥情空心
滥情空心 2021-01-30 20:36

Traditionally, when I\'ve tried to get data for a user from a database, and I\'ve used the following method (to some degree):

DbUsers curUser = context.DbUsers.F         


        
3条回答
  •  春和景丽
    2021-01-30 21:02

    If you need not whole entity, but some values from it, then use new {name = s.u_Name, email = s.u_Email}. Because, this object is much "lighter" for cunstruction. When you get entity with FirstOrDefault, it' saved in DBContext, but you don't do anything with it. So, i advice you to get only data you need.

提交回复
热议问题