DatabaseUtil.SourceGen 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DatabaseUtil.SourceGen --version 0.2.0                
NuGet\Install-Package DatabaseUtil.SourceGen -Version 0.2.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.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DatabaseUtil.SourceGen --version 0.2.0                
#r "nuget: DatabaseUtil.SourceGen, 0.2.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.2.0

// Install DatabaseUtil.SourceGen as a Cake Tool
#tool nuget:?package=DatabaseUtil.SourceGen&version=0.2.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 compliant method on the class [DbRecordReader] and decorate that method with [DbGetField]. The method must return the custom type, the first parameter must be something that implements IDataRecord, and the second parameter must be int.

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.

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 207 4/15/2024
0.3.0 157 3/27/2024
0.2.0 236 3/18/2024
0.1.0 223 3/14/2024

- Source Generator works on standard classes and structs now, but there must be only 1 constructor