private UserAccounts GetOne(int userId) { var dbSession = DbSessionFactory.GetCurrentSession(); var result = dbSession.UserAccountsRepository.LoadEntities(s => s.UserId == userId).SingleOrDefault(); if (result != null) { return(result); } else { result = new UserAccounts() { UserId = userId }; dbSession.UserAccountsRepository.AddEntities(result); if (dbSession.SaveChange() > 0) { return(result); } else { throw new Exception("更新条目出错"); } } }
public ModuleManageBLL() { IDataBaseInfoBll bll = DataBaseInfoFactory.GetDataBaseInfoBll(DataBaseStaticConfig.Config.provider); DbHelper db = bll.SetDbHelperHasDbName(DataBaseStaticConfig.Config); _dbSession = DbSessionFactory.GetDbSession <RLFrameWorkEntities>(db.dbConnectionString); }
public bool SetPassword(string password) { var dataSource = GetOne(this._userId); dataSource.Password = password; dataSource.IsActive = true; return(DbSessionFactory.GetCurrentSession().SaveChange() > 0); }
public void Create_Returns_Db_Session() { DbSessionFactory dbSessionFactory = new DbSessionFactory(Helpers.ConnectionString); IDbSession dbSession = dbSessionFactory.Create(); Assert.IsNotNull(dbSession); }
public void Create_Returns_Db_Session() { InMemoryDb db = new InMemoryDb(); DbSessionFactory dbSessionFactory = new DbSessionFactory(db); IDbSession dbSession = dbSessionFactory.Create(); Assert.IsNotNull(dbSession); }
public void Create_Returns_Db_Session() { DbSessionFactory dbSessionFactory = new DbSessionFactory(Helpers.ConnectionString, Helpers.ResourceAssembly); using (IDbSession dbSession = dbSessionFactory.Create()) { Assert.IsNotNull(dbSession); } }
public List <dynamic> Query_Dynamic_1000() { using (var dbSession = DbSessionFactory.Open(WriteDataSource)) { return(dbSession.Query <dynamic>(new RequestContext { Scope = Scope, SqlId = "Query", Request = new { Taken = TAKEN_1000 } }).ToList()); } }
public IList <AllPrimitive> Query_100() { using (var dbSession = DbSessionFactory.Open(WriteDataSource)) { return(dbSession.Query <AllPrimitive>(new RequestContext { Scope = Scope, SqlId = "Query", Request = new { Taken = TAKEN_100 } })); } }
public List <int> GetNoReadCount(int userID) { //我捞起来的瓶子,有回复的条数 string fishingNoReadSql = @"SELECT count(1) FROM [JointDriftBottleDB].[dbo].[Bottle] where FirstReplyUserID=" + userID + " and LastReplyUserID=CreateUserID And [ReplyViewTime]<[LastReplyTime]"; //我丢出去的瓶子有回复的条数 string throwNoReadSql = @"SELECT count(1) FROM [JointDriftBottleDB].[dbo].[Bottle] where CreateUserID=" + userID + " and LastReplyUserID<>CreateUserID And CreateViewTime<[LastReplyTime]"; IDbSession dbSession = DbSessionFactory.GetCurrentDbSession(); DataTable dtData1 = dbSession.SqlQueryForDataSet(fishingNoReadSql, null).Tables[0]; DataTable dtData2 = dbSession.SqlQueryForDataSet(throwNoReadSql, null).Tables[0]; List <int> countResult = new List <int>(); countResult.Add(Convert.ToInt32(dtData1.Rows[0][0])); countResult.Add(Convert.ToInt32(dtData2.Rows[0][0])); return(countResult); }
public SmartSqlConfig() { Settings = Settings.Default; SqlMaps = new Dictionary <string, SqlMap>(); ObjectFactoryBuilder = new ExpressionObjectFactoryBuilder(); TagBuilderFactory = new TagBuilderFactory(); TypeHandlerFactory = new TypeHandlerFactory(); LoggerFactory = NullLoggerFactory.Instance; DeserializerFactory = new DeserializerFactory(); Properties = new Properties(); IdGenerator = SnowflakeId.Default; DbSessionFactory = new DbSessionFactory(this); SessionStore = new DbSessionStore(DbSessionFactory); StatementAnalyzer = new StatementAnalyzer(); }
/// <summary> /// 添加模板配置 /// </summary> /// <param name="etModel"></param> /// <returns></returns> public bool AddTemplate(ExamineTemplate etModel) { //using (CRDatabase _context = new CRDatabase()) //{ // UserInfo currentUser = new UserInfoService().GetCurrentUser(); // etModel.TEMPLATEID = Guid.NewGuid().ToString(); // etModel.CREATEDATETIME = System.DateTime.Now; // etModel.EDITDATETIME = System.DateTime.Now; // etModel.CREATEUSERID = currentUser.UserId; // etModel.EDITUSERID = currentUser.UserId; // etModel.OWNERID = currentUser.UserId; // etModel.ISDELETED = "0"; // _context.HR_EXAMINETEMPLATE.Add(ModelToEntity(etModel)); // foreach (var templateItem in etModel.TemplateItems) // { // templateItem.TEMPLATEID = etModel.TEMPLATEID; // templateItem.ITEMID = Guid.NewGuid().ToString(); // _context.HR_TEMPLATEITEM.Add(ModelToEntity(templateItem)); // } // return _context.SaveChanges() > 0; //} var context = DbSessionFactory.GetCurrentDbContext(); etModel.TEMPLATEID = Guid.NewGuid().ToString(); //1.添加主表 context.Set <HR_EXAMINETEMPLATE>().Add(ModelToEntity(etModel)); //2.添加项 foreach (var item in etModel.TemplateItems ?? new List <HR_TemplateItemDTO>()) { item.TEMPLATEID = etModel.TEMPLATEID; context.Set <HR_TEMPLATEITEM>().Add(ModelToEntity(item)); //3.添加项单位 foreach (var unitDto in item.ItemUnit ?? new List <HR_TemplateItemUnitDTO>()) { unitDto.ITEMID = item.TEMPLATEID; context.Set <HR_TEMPLATEITEMUNIT>().Add(ModelToEntity(unitDto)); } } return(context.SaveChanges() > 0); }
public DataTable GetBottleListByRd(int userID, DateTime beginTime) { List <SqlParameter> listSqlParameter = new List <SqlParameter>(); listSqlParameter.Add(new SqlParameter { ParameterName = "userID", Value = userID }); listSqlParameter.Add(new SqlParameter { ParameterName = "beginTime", Value = beginTime.ToString("yyyy-MM-dd HH:mm:ss") }); //string sql = @"SELECT TOP 10 * FROM [dbo].[Bottle] where CreateTime>@beginTime ORDER BY NEWID()"; string sql = @"SELECT TOP 10 * FROM [dbo].[Bottle] where FirstReplyUserID is null and CreateUserID<>@userID and CreateTime>=@beginTime ORDER BY NEWID()"; IDbSession dbSession = DbSessionFactory.GetCurrentDbSession(); DataTable dtData = dbSession.SqlQueryForDataSet(sql, listSqlParameter.ToArray()).Tables[0]; return(dtData); }
public SmartSqlConfig() { Settings = Settings.Default; SqlMaps = new Dictionary <string, SqlMap>(); Filters = new FilterCollection(); ObjectFactoryBuilder = new ExpressionObjectFactoryBuilder(); TagBuilderFactory = new TagBuilderFactory(); TypeHandlerFactory = new TypeHandlerFactory(); LoggerFactory = NullLoggerFactory.Instance; DeserializerFactory = new DeserializerFactory(); Properties = new Properties(); IdGenerators = new Dictionary <string, IIdGenerator> { { nameof(SnowflakeId.Default), SnowflakeId.Default } }; DbSessionFactory = new DbSessionFactory(this); SessionStore = new DbSessionStore(DbSessionFactory); StatementAnalyzer = new StatementAnalyzer(); InvokeSucceedListener = new InvokeSucceedListener(); DbSessionFactory.Opened += (sender, args) => { InvokeSucceedListener.BindDbSessionEvent(args.DbSession); }; }
/// <summary> /// 添加依据模板 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool SaveBaseOnTemplate(string historyId, List <BaseTemplateResult> list) { if (list == null) { LogService.WriteInfoLog(logTitle, "试图查找为空的CTMS_BASETEMPLATERESULT实体!"); return(false); } using (var db = DbSessionFactory.GetCurrentDbContext()) { var oldList = db.Set <CTMS_BASETEMPLATERESULT>().Where(p => p.HISTORYID == historyId).ToList(); foreach (var item in oldList) { db.Set <CTMS_BASETEMPLATERESULT>().Remove(item); db.Set <CTMS_IMAGEEXAMINEREPORTDETAIL>().Where(p => p.REPORTID == item.BASETEMPLATEID) .ForEachAsync(k => db.Set <CTMS_IMAGEEXAMINEREPORTDETAIL>().Remove(k)); } foreach (var baseTemplateResult in list) { db.Set <CTMS_BASETEMPLATERESULT>().Add(ModelToEntity(baseTemplateResult)); //结果不序列化成json的存放 Dictionary <string, string> dic = JsonConvert.DeserializeObject <Dictionary <string, string> >(baseTemplateResult.RESULT); if (dic.Count > 0) { foreach (string key in dic.Keys) { CTMS_IMAGEEXAMINEREPORTDETAIL detail = new CTMS_IMAGEEXAMINEREPORTDETAIL(); detail.ID = Guid.NewGuid().ToString(); detail.REPORTID = baseTemplateResult.BASETEMPLATEID; detail.OPTIONID = key; detail.VALUE = dic[key]; db.Set <CTMS_IMAGEEXAMINEREPORTDETAIL>().Add(detail); } } } return(db.SaveChanges() > 0); } }
public BaseService() { dbSession = DbSessionFactory.GetCurrentDbSession(); SetCurrentDal(); }
public BaseService() { this.mDbSession = DbSessionFactory.GetCurrentDbSession(); }
public BaseBll() { dbSession = DbSessionFactory.GetEFSession(); }
public AbstractXmlConfigBuilderTest() { SmartSqlBuilder = new SmartSqlBuilder().UseXmlConfig().Build(); DbSessionFactory = SmartSqlBuilder.GetDbSessionFactory(); DbSession = DbSessionFactory.Open(); }
//private IUserInfoBLL _UserInfoBLL; // public IUserInfoBLL UserInfoBLL // { // get // { // if (_UserInfoBLL == null) // { // _UserInfoBLL = new UserInfoBLL(); // } // return _UserInfoBLL; // } // } public bool SaveChanges() { IDBSession DbSession = DbSessionFactory.CreatDbSession(); return(DbSession.SaveChanges()); }