public void Execute(IJobExecutionContext context) { Console.WriteLine(" ************ 开始执行南航项目:访客撤控 : " + DateTime.Now); var db = new EFContext(); var dateTime = DateTime.Now; var ApplyList = db.Set <VisitorApply>().Where(p => dateTime > p.VisitEndTime && p.SurveyStatus == "0" && p.DhId != null).ToList(); foreach (var apply in ApplyList) { // 闸机Id列表 var zjids = db.Set <Relevance>().Where(p => p.SecondKey == apply.BuildingId && p.Name == Relation.GateBuilding).Select(p => p.FirstKey).ToList(); var channelIds = db.Set <Gate>().Where(t => zjids.Contains(t.Id)).Select(p => p.DeviceNumber + "$7$0$0").ToArray(); var ResultStr = DHAccount.CancelSurvey(channelIds, apply.DhId); var jo = ResultStr.Parse2JObject(); if (jo.Value <bool>("success")) { apply.SurveyStatus = "1"; Console.WriteLine("撤控成功:" + ResultStr + " DhId = " + apply.DhId); } else { Console.WriteLine("撤控失败:" + ResultStr + " DhId = " + apply.DhId); } if (apply.VisitType == "1") { Console.WriteLine("校外访客删除:" + DHAccount.PUSH_DH_DELETE_PERSON(new string[] { apply.DhId })); } } db.SaveChanges(); db.Dispose(); }
/// <summary> /// 处理同步学生信息 学生信息同步6张表 /// 分别为: School_Students,Sys_User,Sys_User_Role,Sys_UserLogOn,Dorm_DormStudent,Dorm_Dorm /// </summary> public void ProcessStudent(EFContext db) { Console.WriteLine("南航项目:开始同步学生信息 --> " + DateTime.Now.ToLocalTime()); var sw = new Stopwatch(); sw.Start(); var newDb = new NHModel(); ///--------- Step1: 更新 School_Students 表数据 ---------/// ProcessSchoolStudentInfo(db, newDb); Console.WriteLine(" *** 同步 School_Students 结束 。"); ///--------- Step2: 更新 Sys_User 表数据 ---------/// ProcessSchoolStudentSysUser(db, newDb); Console.WriteLine(" *** 同步 Sys_User 结束 。"); ///--------- Step3: 更新 Dorm_Dorm 表数据 ---------/// ProcessSchoolStudentDormInfo(db, newDb); Console.WriteLine(" *** 同步 宿舍相关的表 结束 。"); ///--------- Step5: 更新 Dorm_Dorm 表数据 ---------/// ProcessStudentSysUserRole(db, newDb); Console.WriteLine(" *** 同步 用户角色表 结束 。"); //newDb.BulkDelete(newDb.StudentInfoes.ToList()); //批量删除中间表的所有数据 newDb.Dispose(); db.Dispose(); sw.Stop(); Console.WriteLine("南航项目:同步学生信息结束 --> 合计耗时:" + sw.ElapsedMilliseconds / 1000 + "s"); }
public virtual void Dispose(bool dispose) { if (dispose) { _context.Dispose(); } }
public void Dispose() { if (_dbContext != null) { _dbContext.Dispose(); } }
public virtual void Dispose(bool disposing) { if (!this.disposed) { db.Dispose(); } this.disposed = true; }
protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
/// <summary> /// The EF code first. /// </summary> /// <returns>the entity framework code first view.</returns> public ActionResult EFCodeFirst() { int count; int?newCount = null; EFContext context = null; using (MiniProfiler.Current.Step("EF Stuff")) { try { using (MiniProfiler.Current.Step("Create Context")) context = new EFContext(); // this is not correct, as the count from this assignment is never actually used using (MiniProfiler.Current.Step("First count")) count = context.People.Count(); using (MiniProfiler.Current.Step("Insertion")) { var p = new Person { Name = "sam" }; context.People.Add(p); context.SaveChanges(); } // this count is actually used. using (MiniProfiler.Current.Step("Second count")) count = context.People.Count(); const string sql = "Select count(*) from People"; using (MiniProfiler.Current.Step("Get Count from SqlQuery Method - no sql recorded")) { newCount = context.Database.SqlQuery <int>(sql).Single(); } using (MiniProfiler.Current.Step("Get Count using ProfiledConnection - sql recorded")) { using (var conn = new ProfiledDbConnection(context.Database.Connection, MiniProfiler.Current)) { conn.Open(); newCount = conn.Query <int>(sql).Single(); conn.Close(); } } } finally { if (context != null) { context.Dispose(); } } } return(Content(string.Format("EF Code First complete - count: {0}, sqlQuery count {1}", count, newCount))); }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { _context.Dispose(); } } this.disposed = true; }
public void Dispose() { if (_currentTransaction != null) { _currentTransaction.Dispose(); } _currentTransaction = null; if (_context != null) { _context.Dispose(); } _context = null; }
public void Dispose() { try { db.Dispose(); db = null; db = new EFContext(); } catch (Exception ex) { Log.Error(ex.Message, ex); } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). dbContext.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (EFContext != null) { EFContext.Dispose(); EFContext = null; } repositories.Clear(); } } this.disposed = true; }
/// <summary> /// The EF code first. /// </summary> /// <returns>the entity framework code first view.</returns> public ActionResult EFCodeFirst() { int count; EFContext context = null; using (MiniProfiler.Current.Step("EF Stuff")) { try { using (MiniProfiler.Current.Step("Create Context")) context = new EFContext(); // this is not correct, as the count from this assignment is never actually used using (MiniProfiler.Current.Step("First count")) count = context.People.Count(); using (MiniProfiler.Current.Step("Insertion")) { var p = new Person { Name = "sam" }; context.People.Add(p); context.SaveChanges(); } // this count is actually used. using (MiniProfiler.Current.Step("Second count")) count = context.People.Count(); } finally { if (context != null) { context.Dispose(); } } } return(Content("EF Code First complete - count: " + count)); }
public ActionResult EFCodeFirst() { int count; EFContext context = null; using (MiniProfiler.Current.Step("EF Stuff")) { try { using (MiniProfiler.Current.Step("Create Context")) context = new EFContext(); using (MiniProfiler.Current.Step("First count")) count = context.People.Count(); using (MiniProfiler.Current.Step("Insertion")) { var p = new Person { Name = "sam" }; context.People.Add(p); context.SaveChanges(); } using (MiniProfiler.Current.Step("Second count")) count = context.People.Count(); } finally { if (context != null) { context.Dispose(); } } } return(Json(count, JsonRequestBehavior.AllowGet)); }
/// <summary> /// The EF code first. /// </summary> /// <returns>the entity framework code first view.</returns> public ActionResult EFCodeFirst() { int count; int? newCount = null; EFContext context = null; using (MiniProfiler.Current.Step("EF Stuff")) { try { using (MiniProfiler.Current.Step("Create Context")) context = new EFContext(); // this is not correct, as the count from this assignment is never actually used using (MiniProfiler.Current.Step("First count")) count = context.People.Count(); using (MiniProfiler.Current.Step("Insertion")) { var p = new Person { Name = "sam" }; context.People.Add(p); context.SaveChanges(); } // this count is actually used. using (MiniProfiler.Current.Step("Second count")) count = context.People.Count(); const string sql = "Select count(*) from People"; using (MiniProfiler.Current.Step("Get Count from SqlQuery Method - no sql recorded")) { newCount = context.Database.SqlQuery<int>(sql).Single(); } using (MiniProfiler.Current.Step("Get Count using ProfiledConnection - sql recorded")) { using (var conn = new ProfiledDbConnection(context.Database.Connection, MiniProfiler.Current)) { conn.Open(); newCount = conn.Query<int>(sql).Single(); conn.Close(); } } } finally { if (context != null) { context.Dispose(); } } } return Content(string.Format("EF Code First complete - count: {0}, sqlQuery count {1}", count, newCount)); }
protected override void Dispose(bool disposing) { ctx.Dispose(); base.Dispose(disposing); }
/// <summary> /// The EF code first. /// </summary> /// <returns>the entity framework code first view.</returns> public ActionResult EFCodeFirst() { int count; EFContext context = null; using (MiniProfiler.Current.Step("EF Stuff")) { try { using (MiniProfiler.Current.Step("Create Context")) context = new EFContext(); // this is not correct, as the count from this assignment is never actually used using (MiniProfiler.Current.Step("First count")) count = context.People.Count(); using (MiniProfiler.Current.Step("Insertion")) { var p = new Person { Name = "sam" }; context.People.Add(p); context.SaveChanges(); } // this count is actually used. using (MiniProfiler.Current.Step("Second count")) count = context.People.Count(); } finally { if (context != null) { context.Dispose(); } } } return Content("EF Code First complete - count: " + count); }
public void Dispose() { _db.Dispose(); }
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { db.Dispose(); }
public async void Dispose() { _context.Dispose(); }
public void Dispose() { MyDBContext.Dispose(); }
public virtual void Dispose() { _dbContext.Dispose(); }
public void Execute(IJobExecutionContext context) { Console.WriteLine("开始推送异常消息:" + DateTime.Now); //new PushAppMessage().PushReportMessage("*****@*****.**", "Test Message", ""); //DateTime Time = Convert.ToDateTime("2019-06-05 08:00:00"); var Time = DateTime.Now; var dbContext = new EFContext(); //测试阶段: 只推给 罗尉平 老师 var leaderList = dbContext.Set <OrgLeader>().Where(p => p.UserId.Equals("c769eb3d87d6f7468133840f055bc9e6")).ToList(); var PushList = new List <ZhxyPush>(); foreach (var leader in leaderList) { var Ids = new HashSet <string>(); //当前组织机构下属所有组织机构的ID集合 var OrgId = leader.OrgId; var UserId = leader.UserId; var OrgIds = dbContext.Set <Org>().Where(p => p.ParentId.Equals(OrgId)).Select(p => p.Id).ToList(); if (null == OrgIds || OrgIds.Count() == 0) { continue; } foreach (var id in OrgIds) { Ids.Add(id); var SonOrgIds = dbContext.Set <Org>().Where(p => p.ParentId.Equals(id)).Select(p => p.Id).ToList(); if (null == SonOrgIds || SonOrgIds.Count() == 0) { continue; } foreach (var sid in SonOrgIds) { Ids.Add(sid); var SonOfSonOrgIds = dbContext.Set <Org>().Where(p => p.ParentId.Equals(sid)).Select(p => p.Id).ToList(); if (null == SonOfSonOrgIds || SonOfSonOrgIds.Count() == 0) { continue; } foreach (var ssid in SonOfSonOrgIds) { Ids.Add(sid); var SonOfSonOfSonIds = dbContext.Set <Org>().Where(p => p.ParentId.Equals(ssid)).Select(p => p.Id).ToList(); if (null == SonOfSonOfSonIds || SonOfSonOfSonIds.Count() == 0) { continue; } foreach (var sssid in SonOfSonOfSonIds) { Ids.Add(sssid); } } } } Ids.Add(OrgId); if (null != Ids && Ids.Count() != 0) { var DataList = new List <Dictionary <string, object> >(); var Yeatday = Time.Date.AddDays(-1).Date; var userName = dbContext.Set <User>().Where(p => p.Id.Equals(leader.UserId)).Select(p => p.Account).FirstOrDefault(); var NoReturnCount = dbContext.Set <NoReturnReport>().Where(p => Yeatday.Equals(p.CreatedTime) && Ids.Contains(p.ClassId)).ToList().Count(); var LateReturnCount = dbContext.Set <LateReturnReport>().Where(p => Yeatday == p.CreatedTime && Ids.Contains(p.Class)).ToList().Count(); var NoOutCount = dbContext.Set <NoOutReport>().Where(p => Yeatday == p.CreatedTime && Ids.Contains(p.ClassId)).ToList().Count(); var NoReturnDic = new Dictionary <string, object>(); var LateReturnDic = new Dictionary <string, object>(); var NotOutDic = new Dictionary <string, object>(); var DataDic = new Dictionary <string, object>(); NoReturnDic.Add("未归人员数量:", NoReturnCount + "人"); NoReturnDic.Add("URI", ConfigurationManager.AppSettings["NoReturnReport"] + "?OrgId=" + leader.OrgId + "&ReportDate=" + Yeatday.Date.ToString("yyyy-MM-dd")); LateReturnDic.Add("晚归人员数量:", LateReturnCount + "人"); LateReturnDic.Add("URI", ConfigurationManager.AppSettings["LaterReturnReport"] + "?OrgId=" + leader.OrgId + "&ReportDate=" + Yeatday.Date.ToString("yyyy-MM-dd")); NotOutDic.Add("长时间未出人员数量:", NoOutCount + "人"); NotOutDic.Add("URI", ConfigurationManager.AppSettings["NotOutReport"] + "?OrgId=" + leader.OrgId + "&ReportDate=" + Yeatday.Date.ToString("yyyy-MM-dd")); DataDic.Add("date", Yeatday.Date); DataDic.Add("to", userName); DataList.Add(NoReturnDic); DataList.Add(LateReturnDic); DataList.Add(NotOutDic); DataList.Add(DataDic); new PushAppMessage().PushReportMessage(userName, DataList.ToJson(), ""); PushList.Add(new ZhxyPush() { Account = userName, Content = DataList.ToJson(), CreateTime = DateTime.Now, ReportDate = Yeatday.Date }); Console.WriteLine("NHExceptionPush 推送成功:" + userName + " : " + DataList.ToJson()); } } dbContext.Set <ZhxyPush>().AddRange(PushList); dbContext.SaveChanges(); Console.WriteLine(" ********* NHExceptionPush 全部推送成功 "); dbContext.Dispose(); }
public void Dispose() { context.Dispose(); }
public void Dispose() { _ctx.Dispose(); }
/// <summary> /// The EF core. /// </summary> /// <returns>The entity framework core.</returns> public ActionResult EFCore() { int count; int?newCount = null; EFContext context = null; //using (var connection = new ProfiledDbConnection(new SqliteConnection("DataSource=:memory:"), MiniProfiler.Current)) // dotnet\sdk\NuGetFallbackFolder\microsoft.data.sqlite.core\2.0.0\lib\netstandard2.0\Microsoft.Data.Sqlite.dll using (var connection = new SqliteConnection("DataSource=:memory:")) using (MiniProfiler.Current.Step("EF Core Stuff")) { try { connection.Open(); var options = new DbContextOptionsBuilder <EFContext>() .UseSqlite(connection) .Options; using (MiniProfiler.Current.Step("Create Context")) { context = new EFContext(options); } using (MiniProfiler.Current.Step("Create Schema")) { context.Database.EnsureCreated(); } // this is not correct, as the count from this assignment is never actually used using (MiniProfiler.Current.Step("First count")) { count = context.People.Count(); } using (MiniProfiler.Current.Step("Insertion")) { var p = new Person { Name = "sam" }; context.People.Add(p); context.SaveChanges(); } // this count is actually used. using (MiniProfiler.Current.Step("Second count")) { count = context.People.Count(); } using (MiniProfiler.Current.Step("Get Count from SqlQuery Method - no sql recorded")) { newCount = context.People.FromSql("Select * from People").Count(); } using (MiniProfiler.Current.Step("Get Count using ProfiledConnection - sql recorded")) { using (var conn = new ProfiledDbConnection(context.Database.GetDbConnection(), MiniProfiler.Current)) { conn.Open(); newCount = conn.Query <int>("Select Count(*) from People").Single(); conn.Close(); } } } finally { context?.Dispose(); } } return(Content(string.Format("EF Code First complete - count: {0}, sqlQuery count {1}", count, newCount))); }
void IDisposable.Dispose() { efContext.Dispose(); }