I am trying to use LINQ with Npgsql 2.0.11 in .NET v3.5. I am trying to execute the first simple query from a data table, and I found that the syntax sent to Postgresql is SQL Server syntax, not Pgsql syntax causing the server to throw a syntax error.
I added a factory generator to the App.config project, as stated in the documentation: <system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.11.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"/>
</DbProviderFactories>
</system.data>
Here is a snippet:
DbProviderFactory factory = DbProviderFactories.GetFactory("Npgsql"); DbConnection connection = factory.CreateConnection(); connection.ConnectionString = "Server=mydbhost.example.com;UserId=postgres;Database=postgres"; table = new DataContext(connection).GetTable<Project.Model.MyEntity>();
I found that the factory is an instance of Npgsql.NpgsqlFactory (seems correct), and the connection is an instance of Npgsql.NpgsqlConnection. It all seems good. However, when I try to GetTable, the generated SQL syntax contains square brackets and other SQL Server syntax.
What may be missing?
source share