npgsql LINQ 创建 SQL Server sql 语法
我正在尝试在 .NET v3.5 项目中将 LINQ 与 Npgsql 2.0.11 一起使用。我正在尝试从数据表中进行第一个简单查询,我发现发送到 Postgresql 的语法是 SQL Server 语法,而不是 Pgsql 语法,导致服务器抛出语法错误。
我已按照文档的建议将工厂生成添加到项目的 App.config 中:
这是一个片段:
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>();
我发现 factory 是 Npgsql.NpgsqlFactory 的一个实例(似乎是正确的),并且 connection< /strong> 是 Npgsql.NpgsqlConnection 的实例。这一切看起来都不错。但是,当我尝试 GetTable 时,生成的 SQL 语法包含方括号和各种其他 SQL Server 特定语法。
可能缺少什么?
I'm trying to use LINQ with Npgsql 2.0.11 in a .NET v3.5 project. I'm trying my first simple query from a data table, and I've found that the syntax sent to Postgresql is SQL Server syntax, not Pgsql syntax, causing the server to throw a syntax error.
I have added the factory generation to the project's App.config as suggested by 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've found that factory is an instance of Npgsql.NpgsqlFactory (seems right), and connection is an instance of Npgsql.NpgsqlConnection. All that seems good. However, when I attempt to GetTable, the SQL syntax generated contains square brackets and various other SQL Server specific syntax.
What could be missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DataContext 是LinqToSql。 LinqToSql 仅适用于 SqlServer。
也许您打算使用 LinqToEntities 和 ObjectContext?
DataContext is LinqToSql. LinqToSql is for SqlServer only.
Perhaps you meant to use LinqToEntities and ObjectContext?
如果想要将 LINQ to SQL 用于除 Microsoft SQL Server 之外的 RDBMS,则需要第三方程序集。 DBLinq 是一个为其他(开源)数据库提供 LINQ to SQL 功能的项目。
http://code.google.com/p/dblinq2007/
Npgsql 可以配置为实体框架的数据库提供程序遵循此 Npgsql 博客上的文档:
http://npgsql.com/index.php/2009/08/how-to-set-up-entity-framework-npgsql-part-1/
If one wants to use LINQ to SQL for RDBMS other than Microsoft SQL Server, a third-party assembly is required. DBLinq is a project that provides LINQ to SQL functionality for other (open-source) databases.
http://code.google.com/p/dblinq2007/
Npgsql can be configured as a db provider for Entity Framework following the documentation on this Npgsql blog:
http://npgsql.com/index.php/2009/08/how-to-set-up-entity-framework-npgsql-part-1/