Beispiel #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));
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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;
            }
        }
Beispiel #5
0
        public void GetTableName_TableAttribute_AttributeNameProperty()
        {
            var tableName = OrmUtilities.GetTableName(typeof(PersonWithTableAndColumnAttribute));

            tableName.ShouldBe("people");
        }
Beispiel #6
0
        public void GetTableName_NoTableAttribute_ClassName()
        {
            var tableName = OrmUtilities.GetTableName(typeof(PersonWithId));

            tableName.ShouldBe("PersonWithId");
        }