npgsql

Npgsql parameterized query output incompatible with PostGIS

只谈情不闲聊 提交于 2019-12-23 14:21:44
问题 I have this parameterized query in an Npgsqlcommand: UPDATE raw.geocoding SET the_geom = ST_Transform(ST_GeomFromText('POINT(:longitude :latitude)', 4326),3081) WHERE id=:id :longutide and :latitude are double , and id is int . The query that is actually run against the DB looks like this: UPDATE raw.geocoding SET the_geom = ST_Transform(ST_GeomFromText('POINT(((E'-96.6864379495382')::float8) ((E'32.792527154088')::float8))', 4326),3081) WHERE id=((10793455)::int4) Thanks to help from Erwin

Why does my successfully-read Npgsql data disappear?

邮差的信 提交于 2019-12-22 11:29:34
问题 I have the following code shape. It seems that I'm misunderstanding the C# method return values. How is it possible that a "full" enumerator gets returned as an empty one? class ThingDoer { public NpgsqlDataReader DoQuery() { NpgsqlCommand c = new NpgsqlCommand(...); NpgsqlDataReader dataread = c.ExecuteReader(); return dataread; // Debugger confirms that six data are enumerable here. } } ... class OtherThing { public void higherLevelFunction() { NpgsqlDataReader result = myThingDoer.DoQuery(

EntityFramework Npgsql DbConfiguration doesn't work

五迷三道 提交于 2019-12-21 22:04:01
问题 Im trying to configure EntityFramework with Npgsql with code first. EntityFramework 6.1.3 Npgsql 3.0.5 Now, i want to set a custom configuration by a class, let's see: public class DbConfig : DbConfiguration { public DbConfig() { SetProviderFactory("Npgsql", Npgsql.NpgsqlFactory.Instance); SetProviderServices("Npgsql", provider: NpgsqlServices.Instance); SetDefaultConnectionFactory(new NpgsqlConnectionFactory()); } } and my context class: [DbConfigurationType(typeof(DbConfig))] public class

Npgsql 4.0 Parameters and Null Values

戏子无情 提交于 2019-12-21 20:30:04
问题 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

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

╄→гoц情女王★ 提交于 2019-12-21 12:03:03
问题 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? 回答1: 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;

Using a custom attribute in EF7 (core) OnModelCreating

走远了吗. 提交于 2019-12-21 11:05:15
问题 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

How to use Entity Framework + PostgreSQL from connection?

妖精的绣舞 提交于 2019-12-21 04:29:14
问题 I have already seen threads discussing the use of Entity Framework and PostgreSQL with official instructions. Those instructions need to run gacutil for every install which is not so handy for deployment purposes. What I want to do here is passing PostgreSQL connection directly to the DbContext constructor. This is enough for me because I am going to use CodeFirst without designer. This is what I do: public class Context : DbContext { Context(System.Data.Common.DbConnection connection) : base

How to add custom DB provider to be accessible in Visual Studio?

狂风中的少年 提交于 2019-12-21 03:33:13
问题 I wanted to work with custom DB provider in Visual Studio. I need it to use Entity Framework. For example, I downloaded NpgSQL, registered them in GAC: gacutil -i c:\temp\npgsql.dll gacutil -i c:\temp\mono.security.dll and added to machine.config file: <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.6.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" /> But

Dapper Bulk Insert Returning Serial IDs

泄露秘密 提交于 2019-12-20 19:47:22
问题 I am attempting to perform a bulk-insert using Dapper over Npgsql, that returns the ids of the newly inserted rows. The following insert statement is used in both of my examples: var query = "INSERT INTO \"MyTable\" (\"Value\") VALUES (@Value) RETURNING \"ID\""; First, I attempted to add an array of objects with a "Value" property: var values = new[] { new { Value = 0.0 }, new { Value = 0.5 } }; var ids = connection.Query<int>(query, values); However, that fails with the NpgsqlException:

How to pass parameter to sql 'in' statement?

一笑奈何 提交于 2019-12-20 12:35:13
问题 I want to create this query: select * from products where number in ('123', '234', '456'); but I can't find any example of achiving this with Npgsql and NpgsqlParameter. I tried like this: string[] numbers = new string[] { "123", "234" }; NpgsqlCommands cmd = new NpgsqlCommands("select * from products where number in (:numbers)"); NpgsqlParameter p = new NpgsqlParameter("numbers", numbers); command.Parameters.Add(p); but it didn't work ;) 回答1: Pass it as an array: string[] numbers = new