Esempio n. 1
0
        private void Insert(DbContext context, bool skipSelect)
        {
            _parameters = new string[SqlColumns.Count];
            // var ts = DateTime.UtcNow;
            SqlText.AppendLine("SET NOCOUNT ON;");
            PrepareInsertSql();
            var returned = PrepareSelectSql(skipSelect);

            ExecSqlAndUpdateBack(SqlText.ToString(), context, Entity, returned, ParameterValues.ToArray());
            //Debug.WriteLine("  sql elapsed " + (DateTime.UtcNow - ts).TotalMilliseconds);

            /*
             *
             *  string sql = @"SET NOCOUNT ON;
             * INSERT INTO [RecipeNodes] ([ArticleId], [EnrichedArticleId], [IsActive], [IsDefault], [MigrationSourceId], [Name])
             * VALUES (@p0, @p1, @p2, @p3, @p4, @p5);
             * SELECT [Id]
             * FROM [RecipeNodes]
             * WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity();";
             */
        }
Esempio n. 2
0
        private void Insert(DbContext context)
        {
            _parameters = new string[SqlColumns.Length];
            // var ts = DateTime.UtcNow;
            SqlText.AppendLine("SET NOCOUNT ON;");
            PrepareInsertSql();
            var returned = PrepareSelectSql();

            if (returned != null)
            {
                using (var reader = context.Database.ExecuteReader(SqlText.ToString(), ParameterValues.ToArray()))
                {
                    while (reader.DbDataReader.Read())
                    {
                        var v = new object[reader.DbDataReader.FieldCount];
                        reader.DbDataReader.GetValues(v);
                        for (var index = 0; index < returned.Count; index++)
                        {
                            returned[index].ValueWriter.WritePropertyValue(Entity, v[index]);
                        }
                        break;
                    }
                }
            }
            else
            {
                var tmp = context.Database.ExecuteSqlCommand(SqlText.ToString(), ParameterValues.ToArray());
            }
            //Debug.WriteLine("  sql elapsed " + (DateTime.UtcNow - ts).TotalMilliseconds);

            /*
             *
             *  string sql = @"SET NOCOUNT ON;
             * INSERT INTO [RecipeNodes] ([ArticleId], [EnrichedArticleId], [IsActive], [IsDefault], [MigrationSourceId], [Name])
             * VALUES (@p0, @p1, @p2, @p3, @p4, @p5);
             * SELECT [Id]
             * FROM [RecipeNodes]
             * WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity();";
             */
        }
Esempio n. 3
0
 private void PrepareInsertSql()
 {
     SqlText.AppendFormat("INSERT INTO {0} (", TableName);
     Separator = null;
     for (var index = 0; index < SqlColumns.Count; index++)
     {
         var col = SqlColumns[index];
         if (col.IsIdentity || col.IsDatabaseGenerated)
         {
             continue;
         }
         AddSeparator(", ");
         SqlText.Append(Encode(col.ColumnName));
         AddPropertyValue(index);
     }
     SqlText.Append(") values (");
     Separator = null;
     for (var parameterIdx = 0; parameterIdx < ParameterValues.Count; parameterIdx++)
     {
         AddSeparator(", ");
         SqlText.Append($"@p{parameterIdx}");
     }
     SqlText.AppendLine(");");
 }