/// <inheritdoc />
        public string BuildInsertStatement <T>(T dataModel) where T : class
        {
            if (dataModel == null)
            {
                throw new ArgumentNullException(nameof(dataModel));
            }

            var dataModelTable   = dataModel.GetThuriaDataModelTableName();
            var dataModelColumns = dataModel.GetThuriaDataModelColumns(DbContextAction.Create);

            string sqlStatement;

            lock (_insertBuilderLock)
            {
                _insertStatementBuilder.Clear();
                _insertStatementBuilder = _insertStatementBuilder.WithTable(dataModelTable);

                foreach (var currentColumn in dataModelColumns)
                {
                    var propertyValue = dataModel.GetPropertyValue(currentColumn.PropertyName);
                    if (propertyValue == null || propertyValue.Equals(propertyValue.GetType().GetDefaultData()))
                    {
                        continue;
                    }

                    _insertStatementBuilder.WithColumn(currentColumn.ColumnName, propertyValue);
                }

                sqlStatement = _insertStatementBuilder.Build();
            }

            return(sqlStatement);
        }
Esempio n. 2
0
        private string ConstructInsertStatement(object dataModel)
        {
            var dataModelTable   = dataModel.GetThuriaDataModelTableName();
            var dataModelColumns = dataModel.GetThuriaDataModelColumns(TharkAction.Insert);
            var statementBuilder = _statementBuilder.WithTable(dataModelTable);

            foreach (var currentColumn in dataModelColumns)
            {
                var propertyValue = dataModel.GetPropertyValue(currentColumn.PropertyName);
                if (propertyValue.Equals(propertyValue.GetType().GetDefaultData()))
                {
                    continue;
                }

                statementBuilder.WithColumn(currentColumn.ColumnName, propertyValue);
            }

            return(statementBuilder.Build());
        }