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); }
internal static void ExecuteCollectionQuery <EntityType>(ORMCollection <EntityType> ormCollection, SQLBuilder sqlBuilder) where EntityType : ORMEntity { // If an exception occurs, it just means you didn't specify the ORMUnitTestAttribute to the Unit Test. var unitTestAttribute = new StackTrace().GetFrames().Select(x => x.GetMethod().GetCustomAttributes(typeof(ORMUnitTestAttribute), false)).Where(x => x.Any()).First().First() as ORMUnitTestAttribute; DataTable table = null; // IsManyToMany if (unitTestAttribute.MemoryTables.Count > 1) { var tableName = unitTestAttribute.MemoryTables.Where(x => x.EntityType == ormCollection.TableAttribute.EntityType).First().MemoryTableName; table = ORMUtilities.MemoryCollectionDatabase.Fetch(tableName); } else { table = ORMUtilities.MemoryCollectionDatabase.Fetch(unitTestAttribute.MemoryTables[0].MemoryTableName); } using var reader = table.CreateDataReader(); SQLHelper.DataReader <ORMCollection <EntityType>, EntityType>(ormCollection, reader, sqlBuilder); }