Exemple #1
0
        internal static void ExecuteCollectionQuery <EntityType>(ORMCollection <EntityType> ormCollection, SQLBuilder sqlBuilder)
            where EntityType : ORMEntity
        {
            if (UnitTestUtilities.IsUnitTesting)
            {
                UnitTestUtilities.ExecuteCollectionQuery(ormCollection, sqlBuilder);
                return;
            }

            using var connection    = new SqlConnection(DatabaseUtilities.ConnectionString);
            CurrentConnection.Value = connection;

            using var command = new SqlCommand(sqlBuilder.GeneratedQuery, connection);
            command.Connection.Open();

            if (DatabaseUtilities.Transaction.Value != null)
            {
                command.Transaction = DatabaseUtilities.Transaction.Value;
            }

            if (sqlBuilder.SqlParameters != null)
            {
                foreach (SqlParameter sqlParameter in sqlBuilder.SqlParameters)
                {
                    command.Parameters.Add(sqlParameter);
                }
            }

            using var reader = command.ExecuteReader();
            SQLHelper.DataReader <ORMCollection <EntityType>, EntityType>(ormCollection, reader, sqlBuilder);
        }
Exemple #2
0
        internal static void PopulateChildEntity(ORMEntity parentEntity, ORMEntity childEntity, IDataReader reader, SQLBuilder sqlBuilder)
        {
            var(ReaderStartIndex, ReaderEndIndex) = CalculateJoinIndexes(parentEntity, childEntity, sqlBuilder);

            for (int i = 0; i < (ReaderEndIndex - ReaderStartIndex); i++)
            {
                var value = reader.GetValue(ReaderStartIndex + i);

                var propertyName = reader.GetName(ReaderStartIndex + i);

                if (UnitTestUtilities.IsUnitTesting)
                {
                    UnitTestUtilities.PopulateChildEntity(ref propertyName, ref value, childEntity);
                }

                childEntity[propertyName] = value;
            }

            childEntity.ExecutedQuery = "Initialised through parent";

            FinaliaseEntity(childEntity);
        }