Beispiel #1
0
        ///<summary>
        ///获取单个实体对象
        ///</summary>
        /// <param name="strModelID"></param>
        /// <returns></returns>
        public USEREntity GetByID(object strModelID)
        {
            List <USEREntity>           modelList = new List <USEREntity>();
            USEREntity                  model     = new USEREntity();
            string                      strSql    = "select * from TB_USER where Id=@Id";
            Dictionary <string, object> paramDic  = new Dictionary <string, object>();

            paramDic.Add("@Id", strModelID);
            modelList = ChangeReaderToModel(db.ExecuteReader(strSql));
            return(modelList.Count > 0?modelList[0]:null);
        }
Beispiel #2
0
        ///<summary>
        ///新增
        ///</summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Add(USEREntity model)
        {
            string strSql = @"insert into TB_USER values(@Age,@Sex,@Name,@Email,@DTCreate,@HasDelete,@Role)";
            Dictionary <string, object> paramDic = new Dictionary <string, object>();

            paramDic.Add("Age", model.Age);
            paramDic.Add("Sex", model.Sex);
            paramDic.Add("Name", model.Name);
            paramDic.Add("Email", model.Email);
            paramDic.Add("DTCreate", model.DTCreate);
            paramDic.Add("HasDelete", model.HasDelete);
            paramDic.Add("Role", model.Role);

            int effectLine = db.Execute(strSql);

            return(effectLine > 0?true:false);
        }
Beispiel #3
0
        ///<summary>
        ///更新
        ///</summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(USEREntity model)
        {
            string strSql = @"update TB_USER set Age=@Age,Sex=@Sex,Name=@Name,Email=@Email,DTCreate=@DTCreate,HasDelete=@HasDelete,Role=@Role where Id=@Id";
            Dictionary <string, object> paramDic = new Dictionary <string, object>();

            paramDic.Add("Id", model.Id);
            paramDic.Add("Age", model.Age);
            paramDic.Add("Sex", model.Sex);
            paramDic.Add("Name", model.Name);
            paramDic.Add("Email", model.Email);
            paramDic.Add("DTCreate", model.DTCreate);
            paramDic.Add("HasDelete", model.HasDelete);
            paramDic.Add("Role", model.Role);

            int effectLine = db.Execute(strSql, paramDic);

            return(effectLine > 0?true:false);
        }
        public void TestORMContext()
        {
            USEREntity entity = new USEREntity();

            entity.Name     = "TestName";
            entity.Age      = 20;
            entity.Alias    = "我的别名";
            entity.Birthday = DateTime.Parse("1987-07-07");
            entity.IsLocked = 0;
            DAO4USEREntity DAO = new DAO4USEREntity(entity, ctx.Handler);

            DAO.Save();
            Assert.NotNull(entity.UID);

            //复用使用过的Entity之前清空已更改的属性
            entity.ClearChangedProperty();
            entity.Name = "TestName";
            List <USEREntity> list = DAO.GetArrayList();

            Assert.True(list != null && list.Count > 0);

            //复用使用过的DAO对象,重新设置Entity对象
            USEREntity condition = new USEREntity();

            condition.Age = 20;
            DAO.SetEntity(condition);
            list = DAO.GetArrayList();
            Assert.True(list != null && list.Count > 0);

            //使用SQL表达式查询,复用对象之前清空
            condition.ClearChangedProperty();
            DAO.ClearExpression();
            DAO.AddExpression(Expression.Gt("Age", 0));
            DAO.AddExpression(Expression.Lt("Age", 30));
            list = DAO.GetArrayList();
            Assert.True(list != null && list.Count > 0);

            //使用SQL语句查询,复用前清除之前的SQL表达式
            DAO.ClearExpression();
            list = DAO.GetArrayList("Age>0 and IsLocked<>1");
            Assert.True(list != null && list.Count > 0);
        }
Beispiel #5
0
        ///<summary>
        ///将reader转换为model
        ///</summary>
        /// <param name="reader">reader</param>
        /// <returns></returns>
        private List <USEREntity> ChangeReaderToModel(IDataReader reader)
        {
            List <USEREntity> modelList = new List <USEREntity>();

            using (var odr = reader)
            {
                while (odr.Read())
                {
                    USEREntity model = new USEREntity();
                    model.Id        = (int)odr["Id"];
                    model.Age       = (int)odr["Age"];
                    model.Sex       = (byte)odr["Sex"];
                    model.Name      = (string)odr["Name"];
                    model.Email     = (string)odr["Email"];
                    model.DTCreate  = (DateTime)odr["DTCreate"];
                    model.HasDelete = (bool)odr["HasDelete"];
                    model.Role      = (int)odr["Role"];
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Beispiel #6
0
 ///<summary>
 ///更新
 ///</summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Update(USEREntity model)
 {
     return(dal.Update(model));
 }
Beispiel #7
0
 ///<summary>
 ///新增
 ///</summary>
 /// <param name="model"></param>
 public bool Add(USEREntity model)
 {
     return(dal.Add(model));
 }