Linq DataTable Select Specific Column Name
DataTable dt.Select($"ColumnName='{ABC}'");
Apply For C#FrameWork4.0 TLS1.2 / 1.1 / 1.0
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | (SecurityProtocolType)768 | SecurityProtocolType.Tls;
Linq 找出List< Tready >裡,利用reflection找出子類別為AttachTreaty
List< AttachTreaty > modelRider = (from m in List< Tready >
where m.GetType().Equals(typeof(AttachTreaty))
select (AttachTreaty)m).ToList();
Linq DataTable To Model
usercombo = dbRepository.tbUserComboMain.Where(x => x.Prop_AgentID == AgentID).OrderByDescending(x => x.ModifyDate).
Select(x => new PropModel()
{
propId = x.Prop_ID,
propNo = x.Prop_Name,
propType = "C",
dateTime = x.ModifyDate
}).ToList();
Linq 比較A,B 兩個List Model,保留A比B大的部分
tempAppPropModel = (from x in appPropModel
join y in webPropModel on
//一個比較的參數
x.propId equals y.propId into webPropModel2
//兩個比較的參數
//new { propId = x.propId, dateTime = x.dateTime } equals new { propId = y.propId, dateTime = y.dateTime }
rom y in webPropModel2.DefaultIfEmpty()
where (y == null) || (x.dateTime > y.dateTime)
select x).ToList();
取交集(A和B都有),使用IEqualityComparer
public class PropModelComparer : IEqualityComparer< PropModel >
{
public bool Equals(PropModel x, PropModel y)
{
return x.propId == y.propId;
}
public int GetHashCode(PropModel obj)
{
return obj.GetHashCode();
}
}
appPropModel.AddRange(appDelModel.Intersect(webPropModel, new PropModelComparer()).ToList());