MsSql.Adapter.Generator
1.2.0
See the version list below for details.
dotnet add package MsSql.Adapter.Generator --version 1.2.0
NuGet\Install-Package MsSql.Adapter.Generator -Version 1.2.0
<PackageReference Include="MsSql.Adapter.Generator" Version="1.2.0" />
paket add MsSql.Adapter.Generator --version 1.2.0
#r "nuget: MsSql.Adapter.Generator, 1.2.0"
// Install MsSql.Adapter.Generator as a Cake Addin #addin nuget:?package=MsSql.Adapter.Generator&version=1.2.0 // Install MsSql.Adapter.Generator as a Cake Tool #tool nuget:?package=MsSql.Adapter.Generator&version=1.2.0
MsSql.Adapter.Generator
A Source Generator package that generates methods for a class, including associated request & response classes, based on the result.json
file created by dotnet-mssql-collector tool.
This source generator requires the .NET 6 SDK. You can target earlier frameworks like .NET Core 3.1 etc, but the SDK must be at least 6.0.100
Add the package (and required dependencies) to your application using
dotnet add package MsSql.Adapter.Generator
dotnet add package MsSql.Adapter.Standard.Types
dotnet add package MsSql.Adapter.Utils
This adds the <PackageReference>
to your project. You can additionally mark the generator package as PrivateAsets="all"
and ExcludeAssets="runtime"
.
Setting
PrivateAssets="all"
means any projects referencing this one won't get a reference to the MsSql.Adapter.Generator package. SettingExcludeAssets="runtime"
ensures the MsSql.Adapter.Generator.Attributes.dll_ file is not copied to your build output (it is not required at runtime).
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>Latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MsSql.Adapter.Generator" Version="1.0.6" PrivateAssets="all" ExcludeAssets="runtime" />
</ItemGroup>
</Project>
Adding the package will automatically add a marker attribute, [MssqlAdapterAttribute]
, to your project.
To use the generator, add the [MssqlAdapterAttribute]
attribute to a partial class. For example:
namespace Test
{
[MsSqlAdapter]
public partial class DalService
{
}
}
A class which holds the configuration needs to also exist in the same namespace (class name and properties names can be set in the attribute):
namespace Test
{
[DataContract]
public class DalServiceOptions
{
[DataMember(Order = 1)]
public string ConnectionString { get; set; } = "";
[DataMember(Order = 2)]
public string? ConnectionUser { get; set; }
[DataMember(Order = 3)]
public string? ConnectionPassword { get; set; }
}
}
This will generate an interface that can be used by the protobuf-net.Grpc
. For example:
[ServiceContract(Name = "Test.ExampleDatabase.ExampleDatabaseService")]
public interface IDalService
{
Task<FirstStoredProcedureResponse> FirstStoredProcedure(FirstStoredProcedureRequest req);
}
Additional files that can be used in javascript to add support for nullable values are generated in obj/GeneratedFiles/javascript/
folder.
For a boilerplate project which creates a gRPC service check MsSql.Adapter
Preserving usages of the [MsSqlAdapter]
attribute
The [MsSqlAdapter]
attribute is decorated with the [Conditional]
attribute, so their usage will not appear in the build output of your project. If you use reflection at runtime on one of your class
es, you will not find [MsSqlAdapter]
in the list of custom attributes.
If you wish to preserve these attributes in the build output, you can define the MSSQL_ADAPTER_USAGES
MSBuild variable. Note that this means your project will have a runtime-dependency on MsSql.Adapter.Generator.Attributes.dll so you need to ensure this is included in your build output.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<DefineConstants>MSSQL_ADAPTER_USAGES</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MsSql.Adapter.Generator" Version="1.0.6" PrivateAssets="all" />
</ItemGroup>
</Project>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.