Linq/Lamda 常用写法汇总

 

Sql中In的使用

string[] list = new string[] {"a","b","c","xx","yy","zz" };
string[] filter = {"xx","yy","zz"};
var result = list.Where(p => filter.Contains(p));

 

Linq 集合中查询新对象

 var cs = from c in dc.Customers
          select new
                 {
                     CustomerID = c.CustomerID,
                     CustomerName = c.ContactName
                 };

Lamda 集合中查询新对象

var notices = list.Select(c => {Announcement =c.Announcement,IsView=c.IsView});

 

posted on 2017-01-07 10:36  忙碌ing  阅读(127)  评论(0)    收藏  举报

导航