将SQL查询转换为LINQ to Entities Lambda Expression1

时间:2014-05-01 10:25:01

标签: c# sql linq entity-framework lambda

我想将它转换为实体框架Lambda Expression,但我没有得到正确的语法......

此SQL查询的实体框架Lambda表达式是什么:

   DataTable DT=Select CityName,CityId from City order by cityname;

我想将它存储在Datatable中。那么我怎样才能在MVC中使用Linq Lambda表达式....

1 个答案:

答案 0 :(得分:0)

首先将您的上下文实体如下所示

private Entities db = new Entities();

var city = db.cities.select(c => new { c.CityName , c.CityId}).OrderBy(c=> c.CityName);

db.citites.add(city);

db.SaveChanges();

了解更多信息: -

http://onsaurav.blogspot.in/2013/02/beginning-of-entity-framework-with-mvc.html