コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public IUpdateQueryBuilder SetWithoutColumnsFrom <T>(T model, params string[] columns) where T : notnull
 {
     return(SetFromDictionary(ComponentModelHelper.ToDictionary(model, _options.ColumnFormat), columns));
 }
コード例 #5
0
 public IUpdateQueryBuilder SetWithoutIdFrom <T>(T model) where T : notnull
 {
     return(SetFromDictionary(ComponentModelHelper.ToDictionary(model, _options.ColumnFormat), "id"));
 }