Skip to content

Instantly share code, notes, and snippets.

@eschneider999
Last active April 26, 2018 11:57
Show Gist options
  • Save eschneider999/c9058c482a29bc0fe31de1f380a0bf60 to your computer and use it in GitHub Desktop.
Save eschneider999/c9058c482a29bc0fe31de1f380a0bf60 to your computer and use it in GitHub Desktop.
Symbiotic ORM Parallel Load Hierarchy
public void ParallelLoadHierarchyItems()
{
IDatabaseTypesFactory factory = new DatabaseTypesFactorySqlServer();
factory.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\Dev\\FrozenElephant\\SymbioticORM\\SqlDatabase\\SymbioticTestLocal.mdf;Integrated Security=True;Connect Timeout=30";
IObjectLoader loader = factory.CreateObjectLoader();
IList<ISqlQuery> queries = new List<ISqlQuery>();
ISqlQuery s1 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems1", typeof(Person));
queries.Add(s1);
ISqlQuery s2 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems2", typeof(Person));
queries.Add(s2);
ISqlQuery s3 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems3", typeof(Person));
queries.Add(s3);
ISqlQuery s4 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems4", typeof(Person));
queries.Add(s4);
ISqlQuery s5 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems5", typeof(Person));
queries.Add(s5);
ISqlQuery s6 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems6", typeof(Person));
queries.Add(s6);
ISqlQuery s7 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems7", typeof(Person));
queries.Add(s7);
ISqlQuery s8 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems8", typeof(Person));
queries.Add(s8);
ISqlQuery s9 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems9", typeof(Person));
queries.Add(s9);
ISqlQuery s10 = factory.CreateSqlQuery("Select top 2000 * from People", "ParallelLoadHierarchyItems10", typeof(Person));
queries.Add(s10);
IList<IList> data = loader.ParallelLoadHierarchyItems(queries);
IList<Person> p0 = (IList<Person>)data[0];
p0[0].LastName = "Upated:";
if (data.Count == 0)
{
Assert.Fail();
}
}
@eschneider999
Copy link
Author

eschneider999 commented Nov 22, 2016

The parameters of "ParallelLoadHierarchyItems* are just a debugging aid. The text will be included in any error message to help the developer isolate the problem query.

Also the return collection's results order will be in the same order as queried regardless of completion time of each query. In this case they are all the same queries and types, but they can all be different.

The queries are executed and return objects are populated in parallel which can significantly improve performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment