npgsql

npgsql LINQ creates SQL Server sql syntax

你说的曾经没有我的故事 提交于 2019-12-05 18:18:38
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

Npgsql/ Postgresql: “function does not exist” error message when it does

老子叫甜甜 提交于 2019-12-05 12:32:10
scratching my head on this. There's a similar question that might be related at "function does not exist," but I really think it does and PostgreSQL function does not exist but the answer(s) does not seem very obvious. PostgreSQL 9.5. I have an Npgsql-based membership query that looks like this: using (var conn = new NpgsqlConnection(ConnectionString)) { conn.Open(); using (var comm = new NpgsqlCommand("get_user_by_username", conn)) { comm.CommandType = CommandType.StoredProcedure; comm.Parameters.Add("_user_name", NpgsqlDbType.Varchar, 250).Value = username; comm.Parameters.Add("_application

npgsql and Entity Framework code first setup problems

倾然丶 夕夏残阳落幕 提交于 2019-12-05 01:43:10
问题 The most recent error im getting is ERROR: 42P01: relation "dbo.__MigrationHistory" does not exist but im convinced that this is just because something earlier hasnt been set up properly. Im currently trying to set up entity framework 4.4 code first to use Npgsql 2.0.12, I have done the following and it seems to atleast be connecting to the database now but giving me the above error when I do context.saveChanges(); Updated the machine.config for .net 2.0.50727 with; < add name="Npgsql Data

MultipleActiveResultSets for postgresql and ado.net entity data model

馋奶兔 提交于 2019-12-04 18:27:35
Im using visual studio, postgresql database and ado.net entity data model. In the connectionstring, Im unable set MultipleActiveResultSets=True . Usually when I connect to sql server with MultipleActiveResultSets=True , it works fine. but i cannot set the same with postgresql database. When I use this, I got the following error There is already an open DataReader associated with this Command which must be closed first. How do I solve this problem. Multiple Active Result Sets (MARS) is a feature introduced in SQL Server 2005 and is not available in other database systems like postgres so you

Update Asp.net app to Npgsql 3 and removing Preload Reader

馋奶兔 提交于 2019-12-04 17:43:08
I have updated my ASP.NET app from NpgSQL 2.2.5 to 3.0.1. In the breaking changes it's specified that they have removed the Preload Reader support. So I remove it from the string connection. Testing my web app, I got the error "An operation is already in progress." specially in the linq query like this: var plugins = from p in _pluginRepository.GetPlugins() // this method return this: GetAll().OrderBy(p => p.Created) join e in _userPluginRepository.GetByUserId(user.Id).ToList() on p.Id equals e.Plugin.Id into pe from e in pe.DefaultIfEmpty() select new PluginViewModel { Active = e != null,

NHibernate Postgresql DateTime to Time Conversion

久未见 提交于 2019-12-04 15:54:07
I'm using Fluent NHibernate to configure my mappings everything works when reading data but when trying to insert or update records that have a Postgresql type of Time I get the error message "ERROR: 42804: column \"run_time\" is of type time with time zone but expression is of type timestamp without time zone" It looks like NHibernate might be confused on which DbType to convert the DateTime to as you can see from PostgreSQL and C# Datatypes that there are several DbTypes that DateTime map to. I also tried specifying a custom type for this column from IUserType but on the NullSafeSet override

Does Npgsql provider has support for TransactionScope?

 ̄綄美尐妖づ 提交于 2019-12-04 13:12:15
问题 I'm trying to use a TransactionScope with the Npgsql provider. I found in an old question (provider for PostgreSQL in .net with support for TransactionScope) that Npgsql didn't supported it yet. Now, after about 5 years, does Npgsql support TransactionScope? I made a test for myself, using Npgsql 3.0.3 and using the following code: using (var scope = new TransactionScope()) { using(var connection = new Npgsql.NpgsqlConnection("server=localhost;user id=*****;password=*****database=test

Npgsql 4.0 Parameters and Null Values

筅森魡賤 提交于 2019-12-04 11:40:31
Passing a null value using Npgsql looks something like this: using (NpgsqlCommand cmd = new NpgsqlCommand("insert into foo values (:TEST)", conn)) { cmd.Parameters.Add(new NpgsqlParameter("TEST", NpgsqlDbType.Varchar)); cmd.Parameters[0].Value = DBNull.Value; cmd.ExecuteNonQuery(); } Which works fine. The new Npgsql 4.0 documentation recommends declaring parameters with a strong datatype, like this: using (NpgsqlCommand cmd = new NpgsqlCommand("insert into foo values (:TEST)", conn)) { cmd.Parameters.Add(new NpgsqlParameter<string>("TEST", NpgsqlDbType.Varchar)); cmd.Parameters[0].Value =

Using a custom attribute in EF7 (core) OnModelCreating

▼魔方 西西 提交于 2019-12-04 05:16:10
I have a DefaultAttribute defined like so: [AttributeUsage(AttributeTargets.Property)] public class DefaultAttribute : Attribute { /// <summary> /// Specifies this property has a default value upon creation. /// </summary> /// <param name="defaultValue">The default value of the property.</param> /// <param name="useAsLiteral">Set to true if the value is <em>not</em> quoted in the DDL.</param> public DefaultAttribute(object defaultValue, bool useAsLiteral = false) { DefaultValue = defaultValue; UseAsLiteral = useAsLiteral; } public object DefaultValue { get; private set; } /// <summary> ///

How to define 'geography' type using Npgsql and OrmLite (using postgresql, postgis, c#)

隐身守侯 提交于 2019-12-04 04:02:55
How do I define a postgis 'geography' type in my C# class model so that OrmLite can easily pass it through to Postgresql so I can run spatial queries in addition to saving spatial data to the 'geography' column? The best library is NetTopologySuite for this case; you can use like this; protected GisSharpBlog.NetTopologySuite.Geometries.Geometry _geom; public GisSharpBlog.NetTopologySuite.Geometries.Geometry Geom { get { return _geom; } set { _geom = value; } } protected string _geomwkt; public virtual string GeomWKT { get { if (this.Geom != null) return this.Geom.ToText(); else return ""; }