Linq FirstOrDefault

前端 未结 4 1833
醉话见心
醉话见心 2020-12-06 12:16

I have the following LINQ query:

    Manager mngr = (from tr in DataContext.Manager
                    where tr.Name = \"Jones\").FirstOrDefault();
<         


        
4条回答
  •  隐瞒了意图╮
    2020-12-06 13:00

    You are using an ID for the where condition, I think you should've already guaranteed that this query returns only one result.

    If your problem is having no result please check the usage of FirstOrDefault() from MSDN title.

                int[] numbers = { };
                int first = numbers.FirstOrDefault();
                Console.WriteLine(first);
    
                /*
                 This code produces the following output:
    
                 0
                */
    

提交回复
热议问题