LINQ使用Lambda表达式选择几列

学习LINQ的Lambda的表达式,尝试从数据集合中,选择其中几列。

创建一个model:

source code:

namespace Insus.NET.Models
{
    public class ProdImage
    {
        public int ProductID { get; set; }
        public int Type { get; set; }
        public int Priority { get; set; }
        public string Url { get; set; }
        public string Alt { get; set; }
        public string Creator { get; set; }
        public DateTime CreateOn { get; set; }
    }
}
View Code

我们再创建一个实体:



source code:

namespace Insus.NET.Entities
{
  public  class ProdImageEntity
    {
        public IEnumerable<ProdImage> GetProdImage = new List<ProdImage>
        {
            new ProdImage { ProductID = 1,Type=12, Priority=45,
                Url = "http://insus.cnblogs.com", Alt="Insus blogs",
                Creator ="Insus.NET", CreateOn=Convert.ToDateTime("2016-04-13")},

            new ProdImage { ProductID = 2,Type=18, Priority=38,
                Url = "http://www.cnblogs.com/insus", Alt="Insus blogs",
                Creator ="Insus.NET", CreateOn=Convert.ToDateTime("2016-04-18")}
        };
    }
}
View Code

 
接下来,我们就可以演示:

     ProdImageEntity pie = new ProdImageEntity();



你可以选择全部:


在标题中,我们需要选择其中几个字段:

原文地址:https://www.cnblogs.com/insus/p/5403510.html