コード例 #1
0
        /// <summary>
        /// 返回即将要执行的SQL语句
        /// </summary>
        public void Update(List <string> listsql)
        {
            if (this.Id == 0)
            {
                throw new OOEngineException("此对象尚未被持久化,请先执行新增操作后再执行此方法!");
            }
            string        sqlPattern = "update {0} set {1} where Id={2};";
            StringBuilder sbSetValue = new StringBuilder();

            foreach (FieldAttribute pinfo in EInfo.Properties)
            {
                if (sbSetValue.Length > 0)
                {
                    sbSetValue.Append(",");
                }
                sbSetValue.Append(string.Format("{0}={1}", pinfo.FieldName, DLLAnalysis.GetPropertyValue(this, pinfo)));
            }
            foreach (REFAttribute refobj in EInfo.References)
            {
                if (sbSetValue.Length > 0)
                {
                    sbSetValue.Append(",");
                }
                sbSetValue.Append(string.Format("{0}={1}", refobj.REFFieldName, DLLAnalysis.GetReferenceEntityId(this, refobj.PropertyName)));
            }
            if (EInfo.REFSelf)
            {
                if (sbSetValue.Length > 0)
                {
                    sbSetValue.Append(",");
                }
                sbSetValue.Append(string.Format("ParentId={0}", DLLAnalysis.GetReferenceEntityId(this, "Parent" + EInfo.EntityName)));
            }
            string sql = string.Format(sqlPattern, EInfo.EntityName, sbSetValue.ToString(), this.Id);

            if (listsql != null)
            {
                listsql.Add(sql);
            }
        }
コード例 #2
0
        /// <summary>
        /// 执行事务操作时候返回将要执行的SQL语句
        /// </summary>
        public void Insert(List <string> listsql)
        {
            if (this.Id > 0)
            {
                throw new OOEngineException("对象已经被持久化,不能在此对象上执行新增操作!");
            }
            //try
            //{
            string        sqlPattern       = "insert into {0}({1}) values({2});select last_insert_rowid() newid;";
            StringBuilder sbFieldNameList  = new StringBuilder();
            StringBuilder sbFieldValueList = new StringBuilder();

            //常规属性
            foreach (FieldAttribute pinfo in EInfo.Properties)
            {
                if (sbFieldNameList.Length > 0)
                {
                    sbFieldNameList.Append(",");
                }
                sbFieldNameList.Append(pinfo.FieldName);
                if (sbFieldValueList.Length > 0)
                {
                    sbFieldValueList.Append(",");
                }
                sbFieldValueList.Append(DLLAnalysis.GetPropertyValue(this, pinfo));
            }
            //引用属性
            foreach (REFAttribute refobj in EInfo.References)
            {
                if (sbFieldNameList.Length > 0)
                {
                    sbFieldNameList.Append(",");
                }
                //将实体中的REFEntityName转变为数据库表的字段EntityNameId
                sbFieldNameList.Append(refobj.REFFieldName);
                if (sbFieldValueList.Length > 0)
                {
                    sbFieldValueList.Append(",");
                }
                sbFieldValueList.Append(DLLAnalysis.GetReferenceEntityId(this, refobj.PropertyName));
            }
            if (EInfo.REFSelf)
            {
                if (sbFieldNameList.Length > 0)
                {
                    sbFieldNameList.Append(",");
                }
                //将实体中的REFEntityName转变为数据库表的字段EntityNameId
                sbFieldNameList.Append("ParentId");
                if (sbFieldValueList.Length > 0)
                {
                    sbFieldValueList.Append(",");
                }
                sbFieldValueList.Append(DLLAnalysis.GetReferenceEntityId(this, "Parent" + EInfo.EntityName));
            }
            string sql = string.Format(sqlPattern, EInfo.EntityName, sbFieldNameList.ToString(), sbFieldValueList.ToString());

            if (listsql != null)
            {
                listsql.Add(sql);
            }
        }
コード例 #3
0
        /// <summary>
        /// 将新创建的实体插入数据库,如果该实体并不是新建的,则会抛出异常
        /// </summary>
        public virtual void Insert()
        {
            if (this.Id > 0)
            {
                throw new OOEngineException("对象已经被持久化,不能在此对象上执行新增操作!");
            }
            //try
            //{
            string        sqlPattern       = "insert into {0}({1}) values({2});select last_insert_rowid() newid;";
            StringBuilder sbFieldNameList  = new StringBuilder();
            StringBuilder sbFieldValueList = new StringBuilder();

            //常规属性
            foreach (FieldAttribute pinfo in EInfo.Properties)
            {
                if (sbFieldNameList.Length > 0)
                {
                    sbFieldNameList.Append(",");
                }
                sbFieldNameList.Append(pinfo.FieldName);
                if (sbFieldValueList.Length > 0)
                {
                    sbFieldValueList.Append(",");
                }
                sbFieldValueList.Append(DLLAnalysis.GetPropertyValue(this, pinfo));
            }
            //引用属性
            foreach (REFAttribute refobj in EInfo.References)
            {
                if (sbFieldNameList.Length > 0)
                {
                    sbFieldNameList.Append(",");
                }
                //将实体中的REFEntityName转变为数据库表的字段EntityNameId
                sbFieldNameList.Append(refobj.REFFieldName);
                if (sbFieldValueList.Length > 0)
                {
                    sbFieldValueList.Append(",");
                }
                sbFieldValueList.Append(DLLAnalysis.GetReferenceEntityId(this, refobj.PropertyName));
            }
            if (EInfo.REFSelf)
            {
                if (sbFieldNameList.Length > 0)
                {
                    sbFieldNameList.Append(",");
                }
                //将实体中的REFEntityName转变为数据库表的字段EntityNameId
                sbFieldNameList.Append("ParentId");
                if (sbFieldValueList.Length > 0)
                {
                    sbFieldValueList.Append(",");
                }
                sbFieldValueList.Append(DLLAnalysis.GetReferenceEntityId(this, "Parent" + EInfo.EntityName));
            }
            string sql   = string.Format(sqlPattern, EInfo.EntityName, sbFieldNameList.ToString(), sbFieldValueList.ToString());
            int    newid = DBSQLiteHelper.ExecuteScalar(sql);

            this.Id = Convert.ToInt64(newid);
            //}
            //catch (Exception e)
            //{
            //    throw new OOEngineException("在持久化新实体对象时发生异常,地址:BaseEntity.Insert(),具体信息:"+e.Message);
            //}
        }