DatabaseUtil.SourceGen 0.4.0

dotnet add package DatabaseUtil.SourceGen --version 0.4.0                
NuGet\Install-Package DatabaseUtil.SourceGen -Version 0.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DatabaseUtil.SourceGen" Version="0.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DatabaseUtil.SourceGen --version 0.4.0                
#r "nuget: DatabaseUtil.SourceGen, 0.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DatabaseUtil.SourceGen as a Cake Addin
#addin nuget:?package=DatabaseUtil.SourceGen&version=0.4.0

// Install DatabaseUtil.SourceGen as a Cake Tool
#tool nuget:?package=DatabaseUtil.SourceGen&version=0.4.0                

DatabaseUtil.SourceGenerator

To use this, first create a partial class, and decorate it with the [DbRecordReader] attribute. This class will be the class that gets methods generated on it.

Then, decorate classes or structs with [DbRecord]. For every class or struct you decorate, methods will be generated on the class decorated with [DbRecordReader]. These methods get column ordinals, read a single row, read the first or default row, or read an enumerable of rows.

Ideally, decorate records. If not, ensure that the class or struct has only one constructor. Otherwise, you will get an error.

If you have any custom types in your classes/structs decorated with [DbRecord], then all you need to do is create a property of type ISqlConverter<TDb, TNet> on the class [DbRecordReader] and decorate that method with [DbConverter].

You can also override built-in type parsing by doing the same as the above. Enums are read as their underlying integer type.

By default, ordinals are obtained by finding fields that match the parameter names in code. You can change this by using the [HasName] attribute and supplying a custom name. Or, if you want to provide explicit ordinals, ignoring column names entirely, use [HasOrdinal] instead. Note that you need to decorate with [DbRecord(ReadBy.Ordinal)] in order to do this.

As for parameters, can decorate classes, structs, or records with [DbParams] to have an implementation of IDbParamsApplicator<T> generated on the class you decorated with [DbRecordReader] (though the target class will probably change in the future).

By default, the parameter names are the same as the property names. You can change this by decorating it with the [HasName] attribute.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.4.0 196 4/15/2024
0.3.0 153 3/27/2024
0.2.0 232 3/18/2024
0.1.0 217 3/14/2024

- GetField removed; converters are the way to handle converting to and from database values and .net values now.
- [DbParams] now generates an implementation of IDbParamsApplicator on the DbRecordReader. [HasName] works to set the name of the parameter as well.