如何使用EDM LINQ方法查询?

时间:2015-01-12 14:04:26

标签: c# linq entity-framework

如何 LINQ查询语法

var city = from c in _db.SubCategories where c.KategorijaID == stateID select new { c.PodKategorijaID, c.NazivPodKategorije };

更改为 LINQ方法语法

实施例

这是 LINQ查询语法:

    using (var context = new SchoolDBEntities())
{
    var L2EQuery = from st in context.Students
                   where st.StudentName == "Bill"
                   select st;

    var student = L2EQuery.FirstOrDefault<Student>();
 }

这是 LINQ方法语法

  //Querying with LINQ to Entities 
using (var context = new SchoolDBEntities())
{
    var L2EQuery = context.Students.where(s => s.StudentName == "Bill");

    var student = L2EQuery.FirstOrDefault<Student>();

}

2 个答案:

答案 0 :(得分:1)

var city = _db.SubCategories.Where(c => c.KategorijaID == stateID)
                            .Select(c => new { c.PodKategorijaID, c.NazivPodKategorije });

答案 1 :(得分:0)

var city = _db.SubCategories.Where(c => c.KategorijaID == stateID)
           .Select(c => new { c.PodKategorijaID, c.NazivPodKategorije });