public void insert_considers_primitives_and_registered_value_objects() { var cmd = _sut.GetCommandConfiguration(); cmd.SqlText.Should().Be("insert into SomePost (Id,Title,Email,CreatedOn)\n values(@0,@1,@2,@3)"); cmd.Args.ShouldAllBeEquivalentTo(new object[] { _data.Id, _data.Title, _data.Email, _data.CreatedOn }); }
public static async Task <InsertedId> InsertAsync <T>(this DbConnection db, T data, CancellationToken?cancel = null, Action <IInsertableOptions <T> > cfg = null) where T : class { data.MustNotBeNull(); cancel = cancel ?? CancellationToken.None; if (data.IsAnonymousType()) { cfg.MustNotBeNull("You need to specify table name at least"); } var info = db.GetPocoInfo <T>(); var options = info.CreateInsertOptions <T>(); cfg?.Invoke(options); var provider = db.Provider(); var builder = new InsertSqlBuilder(data, provider, options); if (options.IdentityColumn.IsNullOrEmpty()) { var count = await db.ExecuteAsync(builder.GetCommandConfiguration(), cancel.Value); if (count != 0) { return(InsertedId.OkWithNoResult); } return(InsertedId.NotOkWithNoResult); } return(await db.GetValueAsync <InsertedId>(builder.GetCommandConfiguration(), cancel.Value)); }
public static Task <InsertedId> InsertAsync <T>(this DbConnection db, T data, CancellationToken cancel, Action <IInsertableOptions <T> > cfg = null) { var info = db.GetPocoInfo <T>(); var options = info.CreateInsertOptions <T>(); cfg?.Invoke(options); var provider = db.Provider(); var builder = new InsertSqlBuilder(info, data, provider, options); return(db.GetValueAsync <InsertedId>(builder.GetCommandConfiguration(), cancel)); }