I am trying to generate c# classes for Linq (or Entity Framework 6) from an existing PostgreSql database on a Linux . I installed npgsql and Entity Framework 6 in a monodevelop project and I was able to query the database with pure SQL.
But when I try to generate Linq classes using Sqlmetal:
sqlmetal -c "Port=5432;Encoding=UTF-8;Server=myDbServer;Database=MyDatabase;UserId=myUser;Password=mypassword;" --code=model.cs --language=c# --provider=PostgreSql
I get the following error:
sqlmetal: Could not load databaseConnectionType type 'npgsql'. Try using the --with-dbconnection=TYPE option.
I don't know what to put after --with-dbconnection
Currently Npgsql driver is not distributed with Mono (http://www.mono-project.com/docs/about-mono/releases/4.0.0/). There are few possibilites to solve this problem:
Install Npgsql.dll into GAC. To do this, you have to use command:
Npgsql.dll can be retrieved from here: https://github.com/npgsql/npgsql/releases/download/v2.2.5/Npgsql-2.2.5-net45.zip. (Version 2.2.5.0 is given as an example, different version (for example v3) can also be used). After that you can try to rerun sqlmetalPut Npgsql.dll in some folder and add this folder to MONO_PATH env variable. For example, put Npgsql.dll into /usr/local/lib/mono-additional-assemblies and then
After that rerun sqlmetal without --with-dbconnection. Should work.