linq查询结果指定列的两种方式

方式一:

var results = from product in products
                orderby product.Price descending
                select new {
                    product.Name,
                    product.Price
                };

方式二:

 products.Where(pro => pro.Price < 3M).Select(s => new { s.Name, s.Price });

 

查询结果转换到实体里:

方式一:

var list = from q in _db.Page_AdPages
                       where q.IsDelete == "N"
                        orderby q.PageID
                        select new AdPages
                        {
                            PageID = q.PageID,
                            PageName = q.PageName,
                            Flag = (Int32)q.Flag
                        };
            return list.ToList<AdPages>();

方式二:

public List<Admin_CPcompany> GetCpList()
        {
            var result = _db.Admin_CPcompany.Select(s => new Admin_CPcompany { ID=s.ID,CPname=s.CPname,AddTime=s.AddTime,IsDelete=s.IsDelete}).ToList();
            return result;
        }

 

posted @ 2013-11-22 15:51  ``炯``  阅读(5477)  评论(0编辑  收藏  举报