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
Shay Rojansky
@roji
Can you explain why?
Vyacheslav Avdeev
@lsoft
for this
image.png
Shay Rojansky
@roji
The point of preparing is usually so that you can execute the same thing multiple times - it generaly doesn't make sense to prepare, execute only once and then deallocate
Vyacheslav Avdeev
@lsoft
when I press ctrl+c button I want to get a statement that ready to execute against postgress db
Shay Rojansky
@roji
OK, so why not just ask Npgsql to execute it?
Vyacheslav Avdeev
@lsoft
sorry. I don't understand the question :) it's PURPOSE of ctrl-c feature, to copy a ready-to-execute-SQL (with all variables that query uses) inside clipboard... so executing the query with npgsql is just something completely different))
Shay Rojansky
@roji
Ah, I see
Vyacheslav Avdeev
@lsoft
ctrl+c works fine for SQL Server now, I'm doing it for postgres.
Shay Rojansky
@roji
You want to copy it, not execute
So you're looking for a way to make Npgsql do the replace from @p to $1, and then copy out the SQL after that
I don't think it makes sense for Npgsql to expose an API for that... But you can copy the SqlQueryParser I pointed to last time, and do the replacing yourself in your extension
But note that even after you have SQL with $1
Vyacheslav Avdeev
@lsoft
to be accurate I need a $ form of SQL, and a map @p <-> $1
Shay Rojansky
@roji
Yeah, SqlQueryParser is what does this replacing inside Npgsql
Vyacheslav Avdeev
@lsoft
@roji 👍 it will resolve my issue! thanks!
Shay Rojansky
@roji
One thing...
Doing PREPARE/DEALLOCATE may not be the best way here
PG is a bit more difficult here compared to SQL Server: you can't just define variables and use them in SQL
But you can start an anonymous DO block where you have procedural programming capabilities (defining variables etc.)
Vyacheslav Avdeev
@lsoft
foo(integer) is integer is not a "variable" type?
Shay Rojansky
@roji
Maybe your approach with PREPARE can work too
Technically no
Vyacheslav Avdeev
@lsoft
oh.
Shay Rojansky
@roji
But it may work...
It's not necessarily wrong
You can definitely try it. If you run into trouble, you can look at anonymous DO block, which may help
But if it works - it's probably the shorter/simpler way
Vyacheslav Avdeev
@lsoft
Looks like I need to read more about DO and PREPARE statements. Thanks for your tips, Shay! I will take a look at all these points.
Shay Rojansky
@roji
Good luck
Vyacheslav Avdeev
@lsoft
👍
Никита (Nikita)
@zZENiro

Hello everyone! I have an inherited class from DbContext

`
[DbConfigurationType(typeof(NpgsqlDbConfig))]
public class TestNpgsqlContext : DbContext
{
public TestNpgsqlContext()
{

    }

    public TestNpgsqlContext(string connectionString, bool migrate = false) : base(new NpgsqlConnection(connectionString), true)
    {
        Database.SetInitializer(new NpgsqlDbInitializer());
        Database.Initialize(true);

        Database.Connection.StateChange += Connection_StateChange;
    }

    protected TestNpgsqlContext(DbConnection connection, bool ownsConnection) : base(connection, ownsConnection)
    {
    }

    private void Connection_StateChange(object sender, StateChangeEventArgs args)
    {
        // TODO: impl for postgresql
    }

    /// <inheritdoc />
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.AddFromAssembly(typeof(TestNpgsqlContext).Assembly);

        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    }
}

`

And when I try instantiate a new context, it's throws an exception:

{"The store type 'tinyint' could not be found in the Npgsql provider manifest"}

I know that postgres doesn't have 'tinyint' type, but provider trying to convert some of the fileds to this type because of some reason...
Mb I'm using wrong provider or smth else?

Also I tried to use commands in PM Console:

Add-Migration -Name "InitMigration" -ProjectName "Test.Project.Data" -ConfigurationTypeName "Test.Project.Data.NpgsqlMigrations.NpgsqlConfiguration" -ConnectionString "User ID=root;Password=root;Host=192.168.0.11;Port=5432;Database=example.com;" -ConnectionProviderName "Npgsql"

...but i ran into the same exception

Shay Rojansky
@roji
@zZENiro that seems like the old EF6, which we no longer really support (it's highly recommended to use EF Core for all new development).
Not sure how/why exactly your program is trying to use tinyint, but I'd start with a minimal program which works and try to isolate where tinyint gets pulled in
Jan Meznik
@JanmanX

Hi! In ASP.NET in a HostedService, my connection times out with this stack trace: https://dpaste.org/k8PK9
When calling the exact same code from a controller (not a hosted service), it runs just fine

                var conn = new NpgsqlConnection(connectionString);
                await conn.OpenAsync();

Any ideas why it hangs in the hosted service?

Shay Rojansky
@roji
@JanmanX AFAIK there shouldn't be any difference if code is run from a hosted service or from a controller... I'd investigate why the timeout happens exactly (e.g. examine PostgreSQL logs, sniff the network...)
Jan Meznik
@JanmanX

@roji tried to add as many logs as possible. This is what I was able to correlate:
https://dpaste.org/RteYp

It seems that it does connect successfully, but then disconnects immediately after. Not really sure why?

Shay Rojansky
@roji
@JanmanX those like like client-side logs (from the application/host where Npgsql is running) - try looking at the server-side (PostgreSQL) logs
Ah, I see some PG messages there too (is that some sort of unified log?). But the last two messages are from 7 minutes before the exception - are you sure they represent the same connection attempt?
At the end of the day, I can't really help out with why a timeout occurs - Npgsql simply establishes a TCP connection and does normal socket I/O. If there's a timeout, that means Npgsql didn't receive a response within the allotted time, that could be a network issue of some sort, or some other server-side problem...
Jan Meznik
@JanmanX

@roji Ah, sorry, the last logs are indeed 7 minutes before the exception. I retry the connection every minute, and the log contains a lot of the same messages, so I did not correlate them correctly.

Thanks for you help though!

Evan Raffel
@evman182
@roji Do you expect to keep npgsql up with the latest EF Core changes, or just as the previews land? I only ask because with the removal of IRelationalValueBufferFactory in the nightly build of EF Core (which you did, lol), npgsql is throwing an exception. Just wondering if I need to wait until preview5.
Shay Rojansky
@roji
@evman182 I sync from time to time - at the very latest soon after the next EF Core preview. So in general I'd say, wait for the next EFCore.PG preview (once a month); if you really really need something fast, you can always check the main branch and see the latest sync commit, and what it works against on the EF Core side.
And yeah, I frequently do stuff in EF Core and later I need to react to them in EFCore.PG. Sometimes I'm even angry with myself for doing them :)
Evan Raffel
@evman182
thx!
Evan Raffel
@evman182

@roji Think I found a bug in the latest vNext package.
The following query: context.Parents.Where(p => myList.Contains(p.Id) && !p.Children.Any()).ToList();

throws the following exception:

Unhandled expression '[Microsoft.EntityFrameworkCore.Query.SqlExpressions.SelectExpression+ConcreteColumnExpression] Equal ANY([Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlParameterExpression])' of type 'Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal.PostgresAnyExpression' encountered in 'SqlNullabilityProcessor'.
  Source=Microsoft.EntityFrameworkCore.Relational
I think you can prob guess at the model from the query, but I can go into more detail if you want. I tested using SqlServer and there was no exception. Wanted to run it by you here before opening a GH issue in case you were already aware
Shay Rojansky
@roji
Definitely open a github issue - ideally with a runnable code sample (always better than asking to guess the model ;))
Evan Raffel
@evman182