-
Notifications
You must be signed in to change notification settings - Fork 2
The user file
The second nested file, called {MyQuery}Results.cs contains partial classes to let you add your properties and methods to both the repository class and the results poco. When QueryFirst runs, this class is read from, but never written to. Here's an example...
using System;
namespace QFConsoleOnLocalDB
{
[Serializable]
public partial class GetCustomersResults
{
// Partial class extends the generated results class
// Serializable by default, but you can change this here
// Add your supplementary methods and properties here, or
// choose a class name more to your liking :-)
internal void OnLoad()
{
}
}
// POCO factory, called for each line of results. For polymorphic POCOs, put your instantiation logic here.
// Tag the results class as abstract above, add some virtual methods, create some subclasses, then instantiate them here based on data in the row.
// This name follows the root name of the query. You can change it by renaming the parent .sql file.
public partial class GetCustomers
{
GetCustomersResults CreatePoco(System.Data.IDataRecord record)
{
return new GetCustomersResults();
}
}
}
First up, the results class. You may want to add properties that present your results data differently. Do that here. We've included an empty OnLoad() method that's called after all properties have been assigned.
Underneath, you'll see the partial class that completes the repository class. The method implemented here is the factory that instantiates the results class. If you need to implement polymorphic results, you will want to tailor this method.
The namespace and the results class name are read from this file at code generation time. You can rename your results class and your namespace by changing the values in this file, and your changes will be reproduced in the generated code.