//求集合空间。
var cs = sdb.GetCollecitonSpace("dbo");
//求集合。
var coll = cs.GetCollection();
//执行数据插入。
List vList =null;
using (AgileHIS.Entities.DbEntities db = new AgileHIS.Entities.DbEntities())
{
vList= db.HFareDetails.ToList();
//插入。
foreach (var item in vList)
{
coll.Insert(item);
}
System.Console.WriteLine(string.Format("insert {0} records", vList.Count));
System.Console.ReadLine();
}
//按条件修改某一条数据的几个属性值。
var v1 = vList.FirstOrDefault();
v1.Name = string.Empty;
v1.Cash = decimal.Zero;
coll.Update(v1, p => p.ID == v1.ID);
//按条件指量修改,指定某几个必,其他属性全部置空。
coll.Update(p => new HFareDetail { Cash = decimal.Zero, Name = string.Empty, Price = decimal.Zero }, p => p.ChargeTime >DateTime.Now.AddDays(-1));
//依据条件删除
coll.Delete(p => p.ChargeTime > DateTime.Now.AddDays(-1));
//求Count
int count = coll.AsQueryable()
.Where(p => p.SourceID==0)
.Count();
//Linq查询Take\Skip。
var vList2 = coll.AsQueryable()
.Where(p => p.CreateTime > DateTime.Now.Date.AddMonths(-12))
.Skip(10).Take(1000)
.ToList();
System.Console.WriteLine(string.Format("query {0} records", vList.Count));
//Linq查询过。
var vFare = coll.AsQueryable()
.Where(p => p.CreateTime > DateTime.Now.Date.AddMonths(-12))
.FirstOrDefault();
System.Console.WriteLine(vFare);
//Linq\聚合运算,目前因为测试驱动报错,暂未实现
var sum = coll.AsQueryable()
.Where(p => p.CreateTime > DateTime.Now.Date.AddMonths(-12))
.Sum(p => p.Cash);
System.Console.ReadLine();