示例#1
0
        public async Task ReplaceAsync(T obj)
        {
            var propertyContainer = SqlHelpers.ParseProperties(obj);
            var sqlPairs          = string.Join(", ", propertyContainer.PairedProperties);

            var sql = $"UPDATE [{TableName}] SET {sqlPairs} WHERE [Id] = @Id;";

            using (var connection = new SqlConnection(ConnectionString))
            {
                await connection.ExecuteAsync(sql, obj);
            }
        }
示例#2
0
        public async Task ReplaceAsync(Blog blog)
        {
            var propertyContainer = SqlHelpers.ParseProperties(blog);
            var sqlPairs          = string.Join(", ", propertyContainer.PairedProperties);

            var sql = $"UPDATE [Blog] SET {sqlPairs};";

            using (var connection = new SqlConnection(ConnectionString))
            {
                await connection.ExecuteAsync(sql, blog);
            }
        }
示例#3
0
        public async Task CreateAsync(Blog blog)
        {
            var propertyContainer = SqlHelpers.ParseProperties(blog);
            var sqlFields         = string.Join(", ", propertyContainer.EscapedProperties);
            var sqlParameters     = string.Join(", ", propertyContainer.ParameterizedProperties);

            var sql = $"INSERT INTO [Blog] ({sqlFields}) VALUES({sqlParameters});";

            using (var connection = new SqlConnection(ConnectionString))
            {
                await connection.ExecuteAsync(sql, blog);
            }
        }
示例#4
0
        public async Task CreateAsync(T obj)
        {
            obj.Id = MongoDB.Bson.ObjectId.GenerateNewId().ToString();

            var propertyContainer = SqlHelpers.ParseProperties(obj);
            var sqlFields         = string.Join(", ", propertyContainer.EscapedProperties);
            var sqlParameters     = string.Join(", ", propertyContainer.ParameterizedProperties);

            var sql = $"INSERT INTO [{TableName}] ([Id], {sqlFields}) VALUES(@Id, {sqlParameters});";

            using (var connection = new SqlConnection(ConnectionString))
            {
                await connection.ExecuteAsync(sql, obj);
            }
        }