Beispiel #1
0
 /// <summary>
 /// 读取模型实例。
 /// </summary>
 /// <param name="sql">SQL语句。</param>
 /// <param name="cancellationToken">取消标记。</param>
 /// <returns>返回模型实例。</returns>
 protected async Task <TModel> ReadSqlAsync(SqlScript sql, CancellationToken cancellationToken = new CancellationToken())
 {
     using (var reader = await ExecuteReaderAsync(sql.ToString(), sql.Parameters, cancellationToken: cancellationToken))
     {
         if (await reader.ReadAsync(cancellationToken))
         {
             return(Entity.Read <TModel>(reader));
         }
     }
     return(default(TModel));
 }
Beispiel #2
0
 /// <summary>
 /// 读取模型实例。
 /// </summary>
 /// <param name="sql">SQL语句。</param>
 /// <returns>返回模型实例。</returns>
 protected TModel ReadSql(SqlScript sql)
 {
     using (var reader = ExecuteReader(sql.ToString(), sql.Parameters))
     {
         if (reader.Read())
         {
             return(Entity.Read <TModel>(reader));
         }
     }
     return(default(TModel));
 }
Beispiel #3
0
        public void CreateTable(RelationModel relation)
        {
            var a = SQL.CreateTable.CreateTb(relation.TbName);

            foreach (var c in relation.Columns)
            {
                a.AddColumn(c.ColumnName, c.TypeName, c.Size, c.ConstraintsStr);
            }
            SqlScript sql = a.ToSql();

            DbServerProvider.ExcuteNonQuery(CommandType.Text, sql.ToString());
        }
Beispiel #4
0
        /// <summary>
        /// 读取模型实例列表。
        /// </summary>
        /// <param name="sql">SQL语句。</param>
        /// <param name="cancellationToken">取消标记。</param>
        /// <returns>返回模型实例列表。</returns>
        protected async Task <IEnumerable <TModel> > LoadSqlAsync(SqlScript sql, CancellationToken cancellationToken = new CancellationToken())
        {
            var models = new List <TModel>();

            using (var reader = await ExecuteReaderAsync(sql.ToString(), sql.Parameters, cancellationToken: cancellationToken))
            {
                while (await reader.ReadAsync(cancellationToken))
                {
                    models.Add(Entity.Read <TModel>(reader));
                }
            }
            return(models);
        }
Beispiel #5
0
        /// <summary>
        /// 读取模型实例列表。
        /// </summary>
        /// <param name="sql">SQL语句。</param>
        /// <returns>返回模型实例列表。</returns>
        protected IEnumerable <TModel> LoadSql(SqlScript sql)
        {
            var models = new List <TModel>();

            using (var reader = ExecuteReader(sql.ToString(), sql.Parameters))
            {
                while (reader.Read())
                {
                    models.Add(Entity.Read <TModel>(reader));
                }
            }
            return(models);
        }
        protected override void CopyEntityObjectToMetaObject(EntityObject target, MetaObject metaObject)
        {
            // Base Copy
            base.CopyEntityObjectToMetaObject(target, metaObject);

            // Process not updatable field
            DocumentContentVersionEntity srcVersion = (DocumentContentVersionEntity)target;

            #region Index
            // Only if new object
            if (metaObject.ObjectState == MetaObjectState.Created)
            {
                // Calculate max index
                int maxIndex = 0;
                SqlScript selectMaxIndex = new SqlScript();

                selectMaxIndex.Append("SELECT MAX([Index]) AS [Index] FROM [dbo].[cls_DocumentContentVersion] WHERE [OwnerDocumentId] = @OwnerDocumentId");
                selectMaxIndex.AddParameter("@OwnerDocumentId", (Guid)srcVersion.OwnerDocumentId);

                using (IDataReader reader = SqlHelper.ExecuteReader(SqlContext.Current,
                    CommandType.Text, selectMaxIndex.ToString(), selectMaxIndex.Parameters.ToArray()))
                {
                    if (reader.Read())
                    {
                        object value = reader["Index"];
                        if (value is int)
                        {
                            maxIndex = (int)value;
                        }
                    }
                }

                // update index
                metaObject["Index"] = maxIndex + 1;
            }
            #endregion

            // Update State via Custom Method = UpdateState
        }
Beispiel #7
0
        /// <summary>
        /// 获取数据集
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public DataSet GetDataSet(SqlScript sql)
        {
            var res = DbServerProvider.ExcuteDataSet(CommandType.Text, sql.ToString());

            return(res);
        }
Beispiel #8
0
        protected override void CopyEntityObjectToMetaObject(EntityObject target, MetaObject metaObject)
        {
            // Base Copy
            base.CopyEntityObjectToMetaObject(target, metaObject);

            // Process not updatable field
            DocumentContentVersionEntity srcVersion = (DocumentContentVersionEntity)target;

            #region Index
            // Only if new object
            if (metaObject.ObjectState == MetaObjectState.Created)
            {
                // Calculate max index
                int       maxIndex       = 0;
                SqlScript selectMaxIndex = new SqlScript();

                selectMaxIndex.Append("SELECT MAX([Index]) AS [Index] FROM [dbo].[cls_DocumentContentVersion] WHERE [OwnerDocumentId] = @OwnerDocumentId");
                selectMaxIndex.AddParameter("@OwnerDocumentId", (Guid)srcVersion.OwnerDocumentId);

                using (IDataReader reader = SqlHelper.ExecuteReader(SqlContext.Current,
                                                                    CommandType.Text, selectMaxIndex.ToString(), selectMaxIndex.Parameters.ToArray()))
                {
                    if (reader.Read())
                    {
                        object value = reader["Index"];
                        if (value is int)
                        {
                            maxIndex = (int)value;
                        }
                    }
                }

                // update index
                metaObject["Index"] = maxIndex + 1;
            }
            #endregion

            // Update State via Custom Method = UpdateState
        }