npgsql

Retrieve serial ID with Npgsql when inserting with ExecuteScalar

这一生的挚爱 提交于 2019-11-29 06:58:04
I'm trying to insert a row into a PostgreSQL table with a serial primary key and I need to retrieve this column after it was inserted. I got something like this: The table "pais" has 3 columns: id, pais, capital; id is a serial column and is its primary key. NpgsqlCommand query = new NpgsqlCommand("insert into pais(nombre, capital) values(@nombre, @capital)", conn); query.Parameters.Add(new NpgsqlParameter("nombre", NpgsqlDbType.Varchar)); query.Parameters.Add(new NpgsqlParameter("capital", NpgsqlDbType.Varchar)); query.Prepare(); query.Parameters[0].Value = this.textBox1.Text; query

“WHERE x IN y” clause with dapper and postgresql throwing 42601: syntax error at or near \\“$1\\”

孤街醉人 提交于 2019-11-29 05:46:53
I have an array of strings, and I'd like to have a query containing an IN clause, like: "... WHERE t.name IN ('foo', 'bar', 'baz')..>" Here's the final bit of my query, which contains a "where X in Y" clause: ... left join genre_tag_band_join tj on hb.id = tj.band_id or ob.id = tj.band_id left join genre_tags t on tj.genre_tag_id = t.id inner join venues v on e.venue_id = v.id where t.name IN @tagsParam... I make a Dapper call like this var shows = con.Query<Event, Band, Band, GenreTag, Venue, Event>(query, (e, hb, ob, gt, v) => { Event show; ... return e; }, new { tagsParam = tagsArr})

Is there a way to use ARRAYs in Entity Framework + PostgreSql

試著忘記壹切 提交于 2019-11-29 04:38:28
Is it possible to use arrays in Entity Framework with PostgreSql? Suppose, for instance, we had the POCO class public class MyTable { [Key] [Column("gid")] public int Gid { get; set; } [Column("name")] public string Name { get; set; } [Column("email")] public string Email { get; set; } [Column("somedata")] public int[] SomeData { get; set; } } At this point Entity Framework simply does not create the column "somedata" and skips it. Is there a way to do this anyway? And by that I mean not having to use a separate table. Postgres arrays come in handy at times where you want to store a small or

Using npgsql 12 and ef 6 together - have anyone succeeded with it?

做~自己de王妃 提交于 2019-11-29 02:25:51
I'm trying to create a small POC for my boss about the hybrid of npgsql 12 and ef6, created a new project on visual studio created a sample database created the corresponding classes and the dbcontext yet, whenever I try and use ef to access the database I receive the folowing error: The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and

PostgreSQL - best way to return an array of key-value pairs

倾然丶 夕夏残阳落幕 提交于 2019-11-29 01:35:09
I'm trying to select a number of fields, one of which needs to be an array with each element of the array containing two values. Each array item needs to contain a name (character varying) and an ID (numeric). I know how to return an array of single values (using the ARRAY keyword) but I'm unsure of how to return an array of an object which in itself contains two values. The query is something like SELECT t.field1, t.field2, ARRAY(--with each element containing two values i.e. {'TheName', 1 }) FROM MyTable t I read that one way to do this is by selecting the values into a type and then

EntityFramework DbContext lifecycle + Postgres: “An operation is already in progress.”

假装没事ソ 提交于 2019-11-28 09:31:41
问题 I have been messing with the following for a few days now. I have a Nancy app running on Mono, with EntityFramework with Repository pattern and UnitOfWork, and Postgres. Nancy uses TinyIoC as it's IoC container. I have a web app that queues requests on the front-end so the back-end gets hit one request at a time. This all works fine. However, the trouble starts when I run an iOS app that connects to the same back-end and does not queue requests to the backend, firing request sometimes almost

how can I get cursor data with calling stored procedure in npgsql

三世轮回 提交于 2019-11-28 08:58:21
问题 I have looked into materials in www.npgsql.org, but couldn't find how to solve my problem... Table, PostgreSQL [City], [State] "Austin", "TX" "Houston", "TX" "Los Angeles", "CA" "San Diego", "CA" "San Fransisco";"CA" "St.Louis", "MO" Function (stored procedure), PostgreSQL -- Procedure that returns a single result set (cursor) CREATE OR REPLACE FUNCTION show_cities() RETURNS refcursor AS $$ DECLARE ref refcursor; BEGIN OPEN ref FOR SELECT city, state FROM cities; RETURN ref; END; $$ LANGUAGE

How to resolve .net core build error NETDSDK1061 and warning MSB3277

旧巷老猫 提交于 2019-11-28 01:26:15
I´ve had the problem, that my AspNetCore.App-metapackage referenced a lower Version of EntityFrameworkCore (2.1.2), than a EfCore provider package (NpgSql, referencing 2.1.3). The result was the warning MSB3277 ( here is the question ). The quickfix for that was the accepted answer. Another answer pointed out, that I´ve worked with a lower Microsoft.AspNetCore.App package (2.1.1 at that time) than the last stable version (2.1.4). Changing the package Version was not possible (see picture below). I´ve had the same issue with Microsoft.NETCore.App in a class library-project I even didn´t noticed

“WHERE x IN y” clause with dapper and postgresql throwing 42601: syntax error at or near \“$1\”

对着背影说爱祢 提交于 2019-11-27 23:14:09
问题 I have an array of strings, and I'd like to have a query containing an IN clause, like: "... WHERE t.name IN ('foo', 'bar', 'baz')..>" Here's the final bit of my query, which contains a "where X in Y" clause: ... left join genre_tag_band_join tj on hb.id = tj.band_id or ob.id = tj.band_id left join genre_tags t on tj.genre_tag_id = t.id inner join venues v on e.venue_id = v.id where t.name IN @tagsParam... I make a Dapper call like this var shows = con.Query<Event, Band, Band, GenreTag, Venue

Can I use Parallel.For with sql Commands?

隐身守侯 提交于 2019-11-27 19:02:59
问题 I have a class of range public class avl_range { public long start { get; set; } public long end { get; set; } } If I use a normal FOR works perfect, but have to wait for each command to finish and each query take 8 seconds, so 10 queries take 80 seconds. In the Parallel version If I only print the ranges works perfect, but if try to execute the command say is already in progress. {"An operation is already in progress."} How can I solve this? var numbers = new List<avl_range>(); using (var