* .AsEnumerable() Delay execution , Not immediately . When calling .AsEnumerable() When , Nothing actually happened .
* .ToList() It's to do it immediately
* The following two types of query conditions are used AsEnumerable, again ToList, This can be executed directly once , Otherwise, it will be executed many times ToList using
(var db = new DB()) { var list =db.OrderMains.AsEnumerable(); var list2 =
db.Markets.AsEnumerable(); // If one of the query criteria is not empty , Then use the following multi conditional query statement if
(condition.order_Id.IsNotNullOrEmpty()) { list = list.Where(t1 =>
t1.order_Id.Contains(condition.order_Id)); } if
(condition.orderDate.IsNotNullOrEmpty()) { list = list.Where(t1 =>
Convert.ToDateTime(t1.orderDate)>= Convert.ToDateTime(condition.orderDate)); }
if (condition.marketId.IsNotNullOrEmpty()) { list2 = list2.Where(t2 =>
t2.Name.Contains(condition.marketId)); } if
(condition.orderMoney.IsNotNullOrEmpty()) { list = list.Where(t1 =>
Convert.ToDateTime(t1.orderDate) <= Convert.ToDateTime(condition.orderMoney));
} var result = (from t1 in list join t2 in list2 on t1.marketId equals
t2.Market_Id select new { Id = t1.Id, orderDate = t1.orderDate, orderMoney =
t1.orderMoney, marketId = t2.Name, order_Id = t1.order_Id }).ToList(); return
result; }
Please indicate the source of reprint :https://mp.csdn.net/postedit/82746018
<https://mp.csdn.net/postedit/82746018>