T4 templates - OrmLite - Tooling used

I’d like to know which tool(s) you are using with those templates (to generate the code):

It looks like the vs extension that supports this only works with Vs2017 and is pretty old/doesn’t seem to be supported.

Rider now supports T4 but I’m getting this error:
Unhandled Exception: System.NotImplementedException: The method or operation is not implemented.
at JetBrains.EnvDTE.Client.Impl.DteImplementation.get_ActiveSolutionProjects()

(I’ve opened a ticket with them).

Thanks!

It’s just T4 Templates a text generation templating tool that’s built into VS.

But I’d recommend first trying AutoQuery AutoGen for generating the table types and AutoQuery Services for each table in your configured RDBMS. Once your app is running you can save the generated code with:

$ x csharp https://localhost:5001 -path /crud/all/csharp

Then you can disable AutoGen (i.e. by removing GenerateCrudServices) and use the generated AutoQuery Services and datamodels from that point onwards.

I needed to add TextTemplatingFileGenerator to the .tt file Properties -> Advanced -> Custom Tool in Visual studio.

(Riders pick them up automatically but they replied that they have limited support for the envdte library).

Now Vs2019 detect them and I can run and debug them etc.

I already used AutoQuery AutoGen and it worked perfectly.

I’m stuck with a legacy DB that has hundreds of stored procedures… So I was hoping not to have to code them all by hand.

The comment in OrmLite.Core.ttinclude says:

In order to work, the appropriate driver must be registered in the system machine.config file. If you’re
using Visual Studio 2010 the file you want is here:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

I’ve added the suggested entries in machine.config (32 and 64 bits folders) except with the newest versions:

<system.data>
    <DbProviderFactories>
        <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.6.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
        <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
        </DbProviderFactories>
</system.data>

From Visual Studio command line I’ve added the dll in my bid/debug to the gac by running:

gacutil -i .\System.Data.SqlClient.dll
gacutil -i .\System.Data.Odbc.dll
gacutil -i .\System.Data.OleDb.dll

I’m still getting this error in the generated .cs file for the storedprocedure:

// This file was automatically generated by the PetaPoco T4 Template
// Do not make changes directly to this file - edit the template instead
//
// The following connection settings were used to generate this file
//
// Connection String Name: DefaultConnection
// Provider: Microsoft.Data.SqlClient
// Connection String: Server=localhost\SQLEXPRESS;Database=LEGACYDB;Trusted_Connection=True;
// Schema: ``
// Include Views: False

// -----------------------------------------------------------------------------------------
// Failed to load provider Microsoft.Data.SqlClient - Unable to find the requested .Net Framework Data Provider. It may not be installed.
// -----------------------------------------------------------------------------------------

If you have any ideas as to what might be causing this please let me know.

I’ve reboot visual studio etc.

Thanks

Not familiar with this issue but Googling the error turned up this thread which contains some causes/solutions:

I already went through everything on that page yesterday without any luck. I think I still have a old laptop with Vs2010 somewhere I’ll see if I can dig it up and try to run this on it.