public Catalog AddIfNoExist(Catalog entity) { using (DbContext db = new SpiderContext()) { var findEntity = db.Set <Catalog>().Where(o => o.RID == entity.RID).FirstOrDefault(); if (findEntity != null) { return(findEntity); } entity.ID = Guid.NewGuid().ToString().ToUpper(); db.Set <Catalog>().Add(entity); Save(db); return(entity); } }
public Catalog AddIfNoExist(Catalog entity) { using (DbContext db = new SpiderContext()) { var findEntity = db.Set <Catalog>().Where(o => o.CatalogLink == entity.CatalogLink).FirstOrDefault(); if (findEntity != null) { return(findEntity); } entity.ID = Guid.NewGuid(); entity.CreateTime = DateTime.Now; db.Set <Catalog>().Add(entity); Save(db); return(entity); } }
public void Add(T entity) { using (DbContext Context = new SpiderContext()) { Context.Set <T>().Add(entity); Save(Context); } }
public bool TodayIsGetProduct(string RefCatalogLink) { using (DbContext Context = new SpiderContext()) { string rankTime = DateTime.Now.ToString("yyyy-MM-dd"); return(Context.Set <Catalog>().Count(o => o.CatalogLink == RefCatalogLink && o.RankTime == rankTime) > 0); } }
public void AddRange(List <Product> list) { using (DbContext Context = new SpiderContext()) { list.ForEach(l => { l.ID = Guid.NewGuid().ToString().ToUpper(); }); Context.Set <Product>().AddRange(list); Save(Context); } }
public void AddRange(List <Product> list) { using (DbContext Context = new SpiderContext()) { DbSet <Product> dbSetEntity = Context.Set <Product>(); Product first = list[0]; list.ForEach(l => { l.ID = Guid.NewGuid(); }); dbSetEntity.AddRange(list); Save(Context); } }