LINQ Select变量定义 Expression<Func<TSource, TResult>>
public class DataListItem { public string RowID { get; set; } public string BusinessCode { get; set; } public string BusinessDescription { get; set; } public int IsActive { get; set; } } static Expression<Func<base_Business, DataListItem>> expressionSelect = obj => new DataListItem() { RowID = obj.RowID, BusinessCode = obj.BusinessCode, BusinessDescription = obj.BusinessDescription, IsActive = obj.IsActive }; static Func<base_Business, DataListItem> exSelectFunc = expressionSelect.Compile(); void test() { var lsit = entities.base_Business.Where(w => w.IsActive == 0).Select(expressionSelect); var obj = entities.base_Business.Where(w => w.IsActive == 0).FirstOrDefault(); var data = exSelectFunc(obj); }
慎于行,敏于思!GGGGGG