• 00
  • :
  • 00
  • :
  • 00

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);
        }

 

posted @ 2020-10-07 15:00  Garson_Zhang  阅读(424)  评论(0编辑  收藏  举报