public IQueryBuilderBase InsertFrom <T>(IEnumerable <T> models) where T : notnull { var dictionaries = models.Select(m => ComponentModelHelper.ToDictionary(m, _options.ColumnFormat)).ToArray(); if (dictionaries.Length > 0) { InsertFromDictionary(dictionaries.First()); } var values = dictionaries.Skip(1).SelectMany(d => d.Values).Select(v => (IInsertValue) new InsertValue(v)); _query.InsertValues.AddRange(values); return(this); }
public void TestDictionaryToObjectWithOneAsBoolean() { var dict = new Dictionary <string, object?> { { "Id", 1 }, { "Name", "name" }, { "Number", null }, { "Check", 1 }, { "DateTime", TestDateTime } }; var obj = ComponentModelHelper.ToObject <TestObject>(dict); obj.Check.Should().BeTrue(); }
public void TestDictionaryToObjectWithDbNull() { var dict = new Dictionary <string, object?> { { "Id", 1 }, { "Name", "name" }, { "Number", null }, { "check", false }, { "DateTime", DBNull.Value } }; var obj = ComponentModelHelper.ToObject <TestObject>(dict); obj.DateTime.Should().BeNull(); }
public void TestDictionaryToObject() { var dict = new Dictionary <string, object?> { { "Id", 1 }, { "Name", "name" }, { "Number", null }, { "Check", false }, { "DateTime", TestDateTime } }; var obj = ComponentModelHelper.ToObject <TestObject>(dict); obj.Id.Should().Be(1); obj.Name.Should().Be("name"); obj.Number.Should().BeNull(); obj.Check.Should().BeFalse(); obj.DateTime.Should().Be(TestDateTime); }
public void TestSnakeCasedDictionaryToObject() { var dict = new Dictionary <string, object?> { { "id", 1 }, { "name", "name" }, { "number", null }, { "check", false }, { "date_time", TestDateTimeString } }; var obj = ComponentModelHelper.ToObject <TestObject>(dict, new CamelToSnakeColumnFormat()); obj.Id.Should().Be(1); obj.Name.Should().Be("name"); obj.Number.Should().BeNull(); obj.Check.Should().BeFalse(); obj.DateTime.Should().Be(TestDateTime); }
public void TestObjectToDictionary() { var obj = new TestObject { Id = 1, Name = "name", Number = null, Check = false, DateTime = TestDateTime }; var dict = ComponentModelHelper.ToDictionary(obj); dict.TryGetValue("Id", out var id); dict.TryGetValue("Name", out var name); dict.TryGetValue("Number", out var number); dict.TryGetValue("Check", out var check); dict.TryGetValue("DateTime", out var dateTime); id.Should().Be(1); name.Should().Be("name"); number.Should().BeNull(); check.Should().Be(false); dateTime.Should().Be(TestDateTime); }
public void TestObjectToSnakeCasedDictionary() { var obj = new TestObject { Id = 1, Name = "name", Number = null, Check = false, DateTime = TestDateTime }; var dict = ComponentModelHelper.ToDictionary(obj, new CamelToSnakeColumnFormat()); dict.TryGetValue("id", out var id); dict.TryGetValue("name", out var name); dict.TryGetValue("number", out var number); dict.TryGetValue("check", out var check); dict.TryGetValue("date_time", out var dateTime); id.Should().Be(1); name.Should().Be("name"); number.Should().BeNull(); check.Should().Be(false); dateTime.Should().Be(TestDateTime); }
public async Task <IReadOnlyList <T> > ListAsync <T>() where T : new() { return((await ResultsAsync()).MapReadOnly(d => ComponentModelHelper.ToObject <T>(d, _options.ColumnFormat))); }
public IReadOnlyList <T> List <T>() where T : new() { return(Results().MapReadOnly(d => ComponentModelHelper.ToObject <T>(d, _options.ColumnFormat))); }
public IUpdateQueryBuilder SetWithoutColumnsFrom <T>(T model, params string[] columns) where T : notnull { return(SetFromDictionary(ComponentModelHelper.ToDictionary(model, _options.ColumnFormat), columns)); }
public IUpdateQueryBuilder SetWithoutIdFrom <T>(T model) where T : notnull { return(SetFromDictionary(ComponentModelHelper.ToDictionary(model, _options.ColumnFormat), "id")); }