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; } } }
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")} }; } }
接下来,我们就可以演示:
ProdImageEntity pie = new ProdImageEntity();