1.DataTable
DataTable dt = udb.GetAllUser();
DataTable dt1 = new DataTable();
IEnumerable<DataRow> q1 = from r in dt.AsEnumerable()
where r.Field<int>("车间ID") == Convert.ToInt32(车间ID) && r.Field<int>("IsAdmin") == 0
orderby r.Field<int>("车间ID") ascending
select r;
dt1 = q1.CopyToDataTable();
r.Field<int>("车间ID") 这么写也行Convert.ToInt32(r["车间ID"])
2.List
List<DIC_RELA_RAILLINE_NODE> SelectGet =
(from x in DIC_RELA_RAILLINE_NODEs
where x.SUB_LINE_ID == RailTrackLines[i].R_ID.ToString()
orderby x.Center_kilo ascending
select x).ToList();
3.对象关联
var result = from x in SUIs
from y in SUs
where x.JobNumber != y.JobNumber && y.DispatchID == "1"
select new {
Name = x.Name,
Title = x.Name,
Body = x.Name,
};
或者
List<Sale_UserInterface> result =
(from x in SUIs
from y in SUs
where x.JobNumber != y.JobNumber && y.DispatchID == "1"
select x).ToList();
分页的写法
IEnumerable<DataRow> q1 = (from r in dt.AsEnumerable()
orderby r.Field<int>("ID") ascending
select r).Skip(startIndex - 1).Take(pageSize);
Skip和Take
用var
var q1 = (from r in CUs
orderby r.CreateTime ascending
select r).Skip(startIndex - 1).Take(pageSize);
List<Common_User> CUs2 = new List<Common_User>(); CUs2 = q1.ToList();
var query = from l in 色彩s
group l by new { l.色彩ID } into g
select new
{
色彩ID = g.Key.色彩ID,
Score = g.Sum(o => o.Score)
};
double q = db.MenuInfo.Where(p => p.PID == PID).Max(p => p.IOrder);