Esempio n. 1
0
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (!c.Value.GetType().IsPrimitive&& !(c.Value is string))
            {
                var tableType = c.Value.GetType().GetGenericArguments().FirstOrDefault();

                var isVariable = c.Type.GetCustomAttribute <CompilerGeneratedAttribute>() != null;

                if (isVariable)
                {
                    return(base.VisitConstant(c));
                }

                SqlStatementBuilder.TableType = c.Value.GetType();
                SqlStatementBuilder.TableName = OrmUtilities.GetTableName(tableType);
                SqlStatementBuilder.Columns   = OrmUtilities.GetColumns(tableType);
            }
            else
            {
                switch (c.Value)
                {
                case string s:
                    SqlStatementBuilder.AddStringToCondition(s);
                    break;

                case int i:
                    SqlStatementBuilder.AddIntToCondition(i);
                    break;
                }
            }
            return(base.VisitConstant(c));
        }
Esempio n. 2
0
        public void GetColumns_Type_ColumnsNamedCorrectly()
        {
            var columns = OrmUtilities.GetColumns(typeof(PersonWithTableAndColumnAttribute));

            columns.ContainsKey("Id").ShouldBe(true);
            columns.ContainsKey("nomen").ShouldBe(true);
        }
Esempio n. 3
0
        public void GetColumns_Type_ValuesAndTypeCorrect()
        {
            var columns = OrmUtilities.GetColumns(typeof(PersonWithTableAndColumnAttribute));

            columns["Id"].Item1.ShouldBe(typeof(int));
            columns["Id"].Item2.ShouldBeNull();
            columns["nomen"].Item1.ShouldBe(typeof(string));
            columns["nomen"].Item2.ShouldBeNull();
        }
Esempio n. 4
0
        public void GetColumns_Object_ColumnsNamedCorrectly()
        {
            var person = new PersonWithTableAndColumnAttribute();

            var columns = OrmUtilities.GetColumns(person);

            columns.ContainsKey("Id").ShouldBe(true);
            columns.ContainsKey("nomen").ShouldBe(true);
        }
Esempio n. 5
0
        private void SubmitDeletedEntries()
        {
            var deletedObjects = ChangeTracker.DeletedObjects;

            foreach (var deletedObject in deletedObjects)
            {
                _sqlBuilder.TableName = OrmUtilities.GetTableName(deletedObject.GetType());
                _sqlBuilder.Columns   = OrmUtilities.GetColumns(deletedObject);

                _dbDriver.RunDeleteStatement(_sqlBuilder.DeleteStatement);
            }
        }
Esempio n. 6
0
        public void GetColumns_Object_ValuesAndTypeCorrect()
        {
            var person = new PersonWithTableAndColumnAttribute
            {
                Id   = 1,
                Name = "Stefan"
            };

            var columns = OrmUtilities.GetColumns(person);

            columns["Id"].Item1.ShouldBe(typeof(int));
            columns["Id"].Item2.Equals(1).ShouldBe(true);
            columns["nomen"].Item1.ShouldBe(typeof(string));
            columns["nomen"].Item2.Equals("Stefan").ShouldBe(true);
        }
Esempio n. 7
0
        private void SubmitModifiedEntries()
        {
            var modifiedObjects = ChangeTracker.ModifiedObjects;

            foreach (var modifiedObject in modifiedObjects)
            {
                _sqlBuilder.TableName = OrmUtilities.GetTableName(modifiedObject.GetType());
                _sqlBuilder.Columns   = OrmUtilities.GetColumns(modifiedObject);
                _sqlBuilder.IdName    = OrmUtilities.GetPrimaryKeyProperty(modifiedObject.GetType()).Name;

                _dbDriver.RunUpdateStatement(_sqlBuilder.UpdateStatement);

                ChangeTracker.GetEntry(modifiedObject).State = ChangeTrackerEntry.States.Unmodified;
                ChangeTracker.GetEntry(modifiedObject).UpdateOriginals(modifiedObject);
            }
        }
Esempio n. 8
0
        private void SubmitInsertedEntries()
        {
            var insertedObjects = ChangeTracker.InsertedObjects;

            foreach (var objectToInsert in insertedObjects)
            {
                _sqlBuilder.TableName = OrmUtilities.GetTableName(objectToInsert.GetType());
                _sqlBuilder.Columns   = OrmUtilities.GetColumns(objectToInsert);
                _sqlBuilder.IdName    = OrmUtilities.GetPrimaryKeyProperty(objectToInsert.GetType()).Name;

                var newId = _dbDriver.RunInsertStatement(_sqlBuilder.InsertStatement);
                SetId(objectToInsert, newId);

                ChangeTracker.GetEntry(objectToInsert).UpdateOriginals(objectToInsert);
                ChangeTracker.GetEntry(objectToInsert).State = ChangeTrackerEntry.States.Unmodified;
            }
        }