Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 21:30
    roji commented #2307
  • Jan 31 2019 20:35
    YohDeadfall commented #2307
  • Jan 31 2019 10:20
    capan starred npgsql/npgsql
  • Jan 31 2019 06:10
    SeanFarrow synchronize #2308
  • Jan 30 2019 20:37
    austindrenski commented #2308
  • Jan 30 2019 20:37
    pentagra commented #1445
  • Jan 30 2019 20:33
    SeanFarrow commented #2308
  • Jan 30 2019 20:31
    austindrenski commented #2308
  • Jan 30 2019 20:27
    SeanFarrow commented #2308
  • Jan 30 2019 20:09
    austindrenski labeled #2308
  • Jan 30 2019 20:05
    roji commented #1520
  • Jan 30 2019 19:50
    gyzod commented #1445
  • Jan 30 2019 19:06
    SeanFarrow commented #1520
  • Jan 30 2019 18:54
    roji commented #1520
  • Jan 30 2019 18:53
    roji commented #1520
  • Jan 30 2019 18:52
    roji commented #2050
  • Jan 30 2019 18:45
    Trolldemorted commented #2050
  • Jan 30 2019 18:21
    SeanFarrow commented #1520
  • Jan 30 2019 18:16
    SeanFarrow review_requested #2308
  • Jan 30 2019 18:16
    SeanFarrow review_requested #2308
zzzzz146
@zzzzz146
because we are using "await" keyword and so the execution is going to wait until the function body is done executing but it won't end as that function is waiting for data from the database as a table or a cell which is not given by the database as the sql query is wrong
i have reported it, do have a look at it
Shay Rojansky
@roji
That's not how it works - if the SQL query is wrong, you get an error (the call throws an exception). Nothing should hang.
zzzzz146
@zzzzz146
after the error hits, the execution never gets forwarded
thats my problem
the codes below ExecuteReaderAsync() does not run. I tried debugging too, the execution goes into this function but never comes out
Shay Rojansky
@roji
@zzzzz146 you need to submit a code sample - you're most likely encountering some other issue in your own code
Npgsql definitely does not hang if you attempt to execute bad SQL
zzzzz146
@zzzzz146
thanks for helping me in the github @roji
I got a question, how should I log the queries being run on c# to Postgres logging? I am not sure how to achieve this task. I tried with the documentation but it was quiet hard for me to understand.
Shay Rojansky
@roji
Daniel Pittersberger
@danielranorex_gitlab
Hi, I want to use Npgsql with Ranorex (testautomation software), but when installing it says my project is targeting .net 4.8 and there is no assembly reference for 4.8. Is that correct? Will there be a 4.8 reference in future?
Shay Rojansky
@roji
Npgsql should work in .NET Framework 4.8 applications, since it targets .NET Standard 2.0. If you're encountering an issue with that, open a stackoverflow question (tag with "npgsql") and include the project csproj/code.
pinkfloydx33
@pinkfloydx33
Any idea wheb the estimated release of npgsql.efcore 7.0 GA will be?
Alberto Passalacqua
@AlbertoPa
RC2 seems to work in the meantime :-)
Shay Rojansky
@roji
Am currently working on it, should be released in the next few hours if all goes well
pinkfloydx33
@pinkfloydx33
Thanks Shay!
Daniel Pittersberger
@danielranorex_gitlab
Okay maybe I have to look more into that, thanks Shay!
pinkfloydx33
@pinkfloydx33
Is mapping an enum type supported with DbDataSource (via NpgsqlDataSourceBuilder) when using EF Core? Everything works fine if I continue to use the global type mapper, but if I map the enum using the builder I get exceptions about types/operators not existing at first query
Shay Rojansky
@roji
@pinkfloydx33 saw your issue (#2557), this absolutely should be supported. I'll look at it later today.
pinkfloydx33
@pinkfloydx33
Creating many DbDataSource (i.e. per-context) appears to be a bad idea. I've got test classes each using a dedicated postgres container and running in parallel. I was creating a new data source for every new context (so per test). All's well if I run without test-class parallelization, but things go haywire otherwise: random timeouts, "error reading from stream" and EnsureCreated throwing because the db already exists. I fixed it by creating one data source per test fixture/container and now everything is smooth sailing. Did I miss that called out somewhere?
SakuraGone
@SakuraGone
Does anyone know to to use npgsql to connect to a postgre database in visual studio using C#
Alexander Horner
@alexhorner
Hello, according to https://www.npgsql.org/efcore/modeling/generated-properties.html#guiduuid-generation Guid objects which are mapped to the uuid type in Postgres are automatically generated clientside by the provider. I am not having any success with this, the field is not autopopulated by Npgsql. When ValueGeneratedOnAdd() is added to my entity configuration, the value sent to the database is NULL, which results in a non-null constraint violation. When ValueGeneratedOnAdd() is removed from my configuration, it does 1 insert of the empty 00000000-0000-0000-0000-000000000000 GUID, which of course is not correct. How can I get Npgsql to clientside generate these Guids correctly? Thanks!
Alberto Passalacqua
@AlbertoPa
@alexhorner never had that happen either. I have to generate the GUID myself in C# (it works with integers IDs but not with string/GUID)
Alexander Horner
@alexhorner
@AlbertoPa Interesting! Do you create yours as part of the SaveChanges(Async)? That's where I generate my Created and Updated values, and where I intend to put Guid generation if I can't get this working. I would like to push this one further though, might create a GitHub issue depending on the response here, as the documentation is either wrong, or lacking clarity as to methodology
Alberto Passalacqua
@AlbertoPa
I just initialize them when I declare
So when the model is constructed, the GUID isn't null.
Alexander Horner
@alexhorner
@AlbertoPa Fair! I'm trying to prevent as much of that as possible. No Created, Updated, Id or Key fields allowed to be modified. Just generated and updated automatically and modifications are dropped
Alexander Horner
@alexhorner
Opened related issue npgsql/efcore.pg#2565
Alberto Passalacqua
@AlbertoPa
Same, but I didn't find a solution to have the db auto-generate the value
Shay Rojansky
@roji
@pinkfloydx33 each DbDataSource corresponds to a connection pool, so creating one per context amounts to disabilng pooling; that's definitely not how DbDataSource is usually supposed to be used. I'm not sure why you'd get random timeouts or "error reading from stream" errors, unless establishing a new physical connection each time (since pooling is off) itself causes the issue. EnsureCreated throwing because the DB already exists likely isn't related to this - first, it's not supposed to throw at all if the database already exists (hence the "Ensure" in the name). Looking at the basic usage docs (https://www.npgsql.org/doc/basic-usage.html#data-source), it seems pretty clear to me that the same data source is supposed to be used to create multiple connections - did you understand it differently?
Shay Rojansky
@roji
@alexhorner re client-side GUID generation, answered on the issue
Alexander Horner
@alexhorner
@roji Thank you
I have replied and I am about to test your solution
pinkfloydx33
@pinkfloydx33
@roji I guess I understood it correctly, but it didn't occur to me there'd be issues/exceptions if I did use multiples. Keep in mind this was during tests so not during normal usage and I resolved it by creating one per server/database (container). This makes me wonder what happens if someone creates the data source (entire builder or built product) completely within the AddDbContext callback, rather than outside of it as that would be tantamount to the same thing (at least against a single server) and essentially what I was doing in tests. I can pretty reliably recreate the EnsureCreated issue if I revert my single-data-source-fix. I initially solved it by adding a try/catch similar to the ones you already use (but with a different exception filter) which as you said makes no sense given how it's supposed to work. But again, no longer a problem using one datasource per endpoint
Shay Rojansky
@roji
There indeed shouldn't be a problem with creating multiple data sources for the same connection string or database (though there's typically no good reason to do so) - it's very similar to turning off pooling. Creating the data source inside OnConfiguring would lead to this, since OnConfiguring is executed for each context instance. But AddDbContext should cause the callback to only run once, which should have the better result. You may be interested in npgsql/efcore.pg#2542 and dotnet/efcore#29489.
DizzyDeveloper
@DizzyDeveloper
Hi Guys, I have a slight left field question. We are using Npgsql + EF to talk to "good" ole Redshift. However, we have started encountering:Npgsql.PostgresException: 57P01: terminating connection due to session timeout errors. The request itself is pretty straight forward, no joins or particular nasty expressions as part of query. The thing is is I repeat the query it works....so in short, the client makes a call to the route, the error above is thrown, the client then re-invokes the route, then it works -_- The failure is always the first invocation. It is a tad hard to trigger to locally as this only happens in environments that we cannot test against, and cannot replicate it locally. Does anyone have any ideas what\where I could look to see what might be causing this behaviour....note I don't think it is directly an issue in npgsql...just reaching in case someone might be in the know.
milosa
@milosa

Hi, i have a question. I'm using efcore 7, dotnet 7, NpgsqlEntityFrameworkCore.Postgresql 7.0.0
I have a simple test application, generating an API response with data from postgresql.

When I make the first request to this API, i get the correct data from my database. But after the first response (i.e. when i refresh the API page in my browser), i get this error (first 3 lines):

System.InvalidOperationException: The ConnectionString property has not been initialized.
   at Npgsql.NpgsqlConnection.Open(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.OpenAsync(CancellationToken cancellationToken)

This is the AddDbContext call in my program.cs:

builder.Services.AddDbContext<PriceListDbContext>(options =>
{
    var dbDataSource = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("PriceListDB"));
    Console.WriteLine(builder.Configuration.GetConnectionString("PriceListDB"));
    dbDataSource.MapEnum<PackagingAmountType>();
    options.UseNpgsql(dbDataSource.Build());
}

Any ideas what might be going on here?

Shay Rojansky
@roji
The code looks ok - I'm assuming you've already checked that the connection string from configuration isn't null... If so, can you open an issue on https://github.com/npgsql/efcore.pg and submit a minimal repro so I can investigate?
milosa
@milosa
Yeah that's why i had the Console.WriteLine in there... I'll make an issue on github
milosa
@milosa
I created the issue: npgsql/efcore.pg#2576
If you need more info or code, let me know.
I'm using postgresql 15 in docker btw
cerkoid
@cerkoid
Hi. Can you help me understand some strange behaviour. We are using EF7.
cerkoid
@cerkoid
Given iteration: pooledfactory.createcontext, add entity, savechanges async... Average insert takes around 0.3 ms. Add await Task.Delay(100) in each iteration and measure only savechanges... It averages 5ms per insert. Connection pooling is enabled... Why would delay change performance from 0.3ms to 5ms... This benchmark was done using benchmark.net. Using sqlite, timings are always 2ms... Why are we experiencing such behaviour?
cerkoid
@cerkoid
Why inserts in quick succession using contexts from pooledfactory whould execute as 'expected' but periodic inserts would experience some 'overhead'. Is this expected behaviour?
Shay Rojansky
@roji
@cerkoid I'd need to see the actual benchmark code to be able to answer that, adding a small delay definitely shouldn't make SaveChanges run slower
cerkoid
@cerkoid
@roji tnx for response. My point exactly. I dont understand which concept in communication from my code to DB with already opened connection (from pool) could be responsible for such delay... Will prepare a sample bench project.
Bjørn E Moe
@cocytus
NpgsqlDataSourceBuilder.MapEnum<> does not replace NpgsqlConnection.GlobalTypeMapper.MapEnum<>, am I correct? Even though GlobalTM is marked as obsolete? Because without doing MapEnum on GTM, i get the error that npgsql is shipping integers to the db, when it expected an enum type.
Or: I can't get the sourceBuilder.MapEnum to work.