Finding entities using a query
DbSet and IDbSet implement IQueryable and so can be used as the starting point for writing a LINQ query against the database. This is not the appropriate place for an in-depth discussion of LINQ, but here are a couple of simple examples:
- using (var context = new BloggingContext())
- {
- // Query for all blogs with names starting with B
- var blogs = from b in context.Blogs
- where b.Name.StartsWith("B")
- select b;
- // Query for the Blog named ADO.NET Blog
- var blog = context.Blogs
- .Where(b => b.Name == "ADO.NET Blog")
- .FirstOrDefault();
- }
تو کد اولی اینجوری متوجه شدم که همون کد اس کیول ای ماست که select کن نام هایی که اولشون با B شروع میشه اما در مورد خط دومی نفهمیدم چی شده !! از این چی میخاد
ADO.NET Blog و این متد به چی اشارهFirstOrDefault میکنه؟