Linq语句简单应用
select p;
q.Dump();
//查询
var w= from p in Products
where p.CateoryId==1
select new {p.ProductName,p.UnitPrice};
w.Dump();
//按照是否供应分组,显示数量
var hh= from p in Products
group p by p.IsAbord into g
select new {g.Key,Nums=g.Count()};
//按类别分组,显示数量
var ww= from p in Products
group p by p.Category.CategoryName into g
select new {g.Key,Nums=g.Count()};
//阻抗失调,所有数据文件都用from读写
var xml=new XElement("Products",
from p in Products
select new XElement("Product",
new XElement("ProductName",p.ProductName),
new XElement("UnitPrice",p.UnitPrice),
new XAttribute("Category",p.Category.CategoryName))
);
xml.Dump();
xml.Save(@"E:\Products.xml");
//XML文档查询
xml.Elements("Product").Where(e=>e.Element("ProductName").Value.Contains("肉")).Dump();//XML代表根节点
//新增
Shipper s=new Shipper{ShipperName="EMS",Tel="010-12345678"};
Shippers.InsertOnSubmit(s);
SubmitChanges();
//修改
Shippers.FirstOrDefault(s=>s.ShipperId==5).ShipperName="EMSEMS";
SubmitChanges();
//删除
Shipper sss=Shippers.FirstOrDefault(sh=>sh.ShipperId==6);
Shippers.DeleteOnSubmit(sss);
SubmitChanges();
//批量删除
var qq=Shippers.Where(sq=>sq.ShipperId>=3);
Shippers.DeleteAllOnSubmit(qq);
// Define other methods and classes here