Example #1
0
 public async Task <IEnumerable <T> > FindList <T>(string strSql, DbParameter[] dbParameter) where T : class
 {
     using (var dbConnection = dbContext.Database.GetDbConnection())
     {
         var reader = await new DbHelper(dbContext, dbConnection).ExecuteReadeAsync(CommandType.Text, strSql, dbParameter);
         return(DatabasesExtension.IDataReaderToList <T>(reader));
     }
 }
Example #2
0
        public async Task LinqGetSqlTest()
        {
            string            sort              = "RoleSort";
            bool              isAsc             = false;
            int               pageSize          = 10;
            int               pageIndex         = 1;
            RepositoryFactory repositoryFactory = new RepositoryFactory();
            var               tempData          = repositoryFactory.BaseRepository().db.dbContext.Set <RoleEntity>().AsQueryable();

            tempData = DatabasesExtension.AppendSort <RoleEntity>(tempData, sort, isAsc);
            tempData = tempData.Skip <RoleEntity>(pageSize * (pageIndex - 1)).Take <RoleEntity>(pageSize).AsQueryable();
            string strSql = DatabasesExtension.GetSql <RoleEntity>(tempData);

            Assert.IsTrue(strSql.ToUpper().Contains("SELECT"));
        }
Example #3
0
        public async Task <int> Update <T>(T entity) where T : class
        {
            dbContext.Set <T>().Attach(entity);
            Hashtable props = DatabasesExtension.GetPropertyInfo <T>(entity);

            foreach (string item in props.Keys)
            {
                if (item == "Id")
                {
                    continue;
                }
                object value = dbContext.Entry(entity).Property(item).CurrentValue;
                if (value != null)
                {
                    dbContext.Entry(entity).Property(item).IsModified = true;
                }
            }
            return(dbContextTransaction == null ? await this.CommitTrans() : 0);
        }