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
Sajan
@woodsongem

sample code:
Unit test case:

        [Fact]
        public void test()
        {
            imdbContext context = GetDBContect();
            Rating rating = new Rating();
            rating.AverageRating = 90;
            rating.NumVotes = 90;
            rating.Tconst = "TC891549";
            context.Add(rating);
            rating = new Rating();
            rating.AverageRating = 90;
            rating.NumVotes = 90;
            rating.Tconst = "TC15491";
            context.Add(rating);
            rating = new Rating();
            rating.AverageRating = 90;
            rating.NumVotes = 90;
            rating.Tconst = "TC15492";
            context.Add(rating);
            context.SaveChanges();
            IMDBProvider iMDBProvider = new IMDBProvider(context);
            IOrderedQueryable<Rating>  ratings = iMDBProvider.GetRatings();
           int ratingCount = ratings.Count();
        }

        private imdbContext GetDBContect()
        {
            DbContextOptions<imdbContext> options;
            var builder = new DbContextOptionsBuilder<imdbContext>();
            builder.UseInMemoryDatabase("DBTestDataBase");
            options = builder.Options;

            imdbContext imdbContext = new imdbContext(options);
            imdbContext.Database.EnsureDeleted();
            imdbContext.Database.EnsureCreated();
            return imdbContext;
        }

Provide code to search context:

public IOrderedQueryable<Rating> GetRatings()
        {
            string sortedBy = "AverageRating";

            return _context.Ratings
            .Where(x => EF.Functions.TrigramsAreSimilar(x.Tconst, "1549") ||
            EF.Functions.TrigramsAreSimilar(x.NumVotes.ToString(), "1549"))
            .OrderBy(p => EF.Property<object>(p, sortedBy));
        }

Error Message:
"The 'TrigramsAreSimilar' method is not supported because the query has switched to client-evaluation. This usually happens when the arguments to the method cannot be translated to server. Rewrite the query to avoid client evaluation of arguments so that method can be translated to server."

mevgenich
@mevgenich
Hey guys,
I'm just wondering when to expect hotfix 5.0.6 available on nuget.org? I'm waiting for a specific fix related to the "Home" env variable on AWS Lambda.
Chris Ochs
@gamemachine
If I'm querying a bytea it looks like postgres doesn't store it's length right? So if I want to use NpgsqlDataReader.GetBytes to avoid allocating I need to store the length in another column?
Alberto Passalacqua
@AlbertoPa
Hello, is there a known issue with preview 4 about connection errors? All seems to work fine in my setup, but when I issue an Update-Database in the package manager console, I have an error message saying there was an error when connecting to the DB. However, all operations work fine and the update is applied.
Shay Rojansky
@roji
@gamemachine PostgreSQL definitely knows the length of bytea, and Npgsql does too when reading it. If you want to use GetBytes to avoid allocating, that means you've already allocated a byte[] buffer to read into; you tell GetBytes how many maximum bytes to read (typically the size of your buffer), and GetBytes will tell you how much it read. If it's less than your buffer, great - you have the entire value. If not, you need to invoke GetBytes again (and possibly again) until you get the rest of the data.
@AlbertoPa no issue as far as I'm aware with preview4... If you think you're seeing an actual problem, please post an issue with a repro.
Alberto Passalacqua
@AlbertoPa
@roji thanks. All I am seeing is a very vague error saying there was a connection issue, but then everything works as expected. I'll try to repro on a clean template app with p5, since it is out :-)
Sam Shirley
@sshirley
Hi everyone. I'm wondering about the PostgresException type. There is a method on there called IsTransient (returns a bool). Does anyone know how that's calculated?
Nevermind. I found it. :-)
msmithmis
@msmithmis
Hello. Can someone show an example of how to send DEFAULT as a parameter in an npgsql update statement? An example query: UPDATE weather SET (temp_lo, temp_hi, prcp) = (temp_lo+1, temp_lo+15, DEFAULT). I want to send the values as parameters. I am not sure how to send DEFAULT, the other ones I can do.
Shay Rojansky
@roji
@msmithmis AFAIK you need to use a literal DEFAULT - I don't think there's any way to parameterize that.
msmithmis
@msmithmis
@roji Ok, thanks. I was hoping to replace parameters that were null with keyword DEFAULT since the field is defined as NOT NULL with a DEFAULT. I guess I will have to add code to leave out the field from the SQL if the value is null and should use the DEFAULT value.
Erik
@ErikOwsiak
@roji can npgsql be used with .net 5 & TimescaleDB ???
Atulin
@Atulin

I have a bit of an issue with using HashSet<T> properties.
I have a model like

class Thing {
  public HashSet<long> Foos { get; init; }
}

configured with

builder.Property(cr => cr.Foos)
    .HasConversion(
        v => new List<long>(v),
        v => new HashSet<long>(v)
    );

because Npg doesn't support HashSet<T> directly.
Problem is, doing .Add() or .Remove() on that property, and then SaveChangesAsync()ing them, doesn't actually update anything in the database

Atulin
@Atulin
A property with a backing property is what I came up with for a potential solution
class Thing
{
  public List<long> Foos { get; set; }
  [NotMapped]
  public HashSet<long> FoosProxy {
    get => new HashSet<long>(Foos);
    set => Foos = new List<long>(value);
  }
}
It's insane enough to maybe just work, because no sane solution seems to
Atulin
@Atulin
Property with a backing property does not work, RIP
Atulin
@Atulin
Found the issue, the change tracker does not recognize the hashset property as changed, since it's the inside of it that changes, not it itself.
jccaso
@jccaso:matrix.org
[m]
hi anybody could help me with "the type initializer for 'npgsql.npgsqlconnection' threw an exception", thanks
Shay Rojansky
@roji
@jccaso:matrix.org please open an issue with the full exception stack trace and a code sample - it's not really possible to help with just that sentence.
Sajan
@woodsongem
Good Morning All,
We are storing FirstName and lastName separate columns in the Customer Table. We are using Trigram search to filter FirstName and lastName. They have separate indexes for FirstName and LastName. also using order by FirstName and lastName.
We are planning to combine FirstName and LastName into a FullName single column and create index, search, order by. Which option is better: Single column or multiple column ? Please share your thoughts. thanks in advance.
nguyencongle
@nguyencongle
Hi all, is it able to use the multi hosts features in this: https://www.npgsql.org/doc/failover-and-load-balancing.html. If not, is there any recommended way to connect to a postgres cluster? Thanks in advance
Shay Rojansky
@roji
@nguyencongle you can use that feature, but you have to use an Npgsql 6.0 preview version. Other than that, it depends on which kind of cluster you're connecting to, in some cases (e.g. cloud) the cluster exposes just one endpoint and manages all the failover/load balancing behind the scenes, so you don't need client support.
nguyencongle
@nguyencongle
Thanks @roji , because I setup the cluster myself so I need the client support. I only need to use the failover feature. Is the preview good to use in production? Do we have a time to release it?
Shay Rojansky
@roji
I'd definitely consider using the preview - it passes all our regular testing and should be quite stable. 6.0 should be released in November along with .NET 6
nguyencongle
@nguyencongle
Thanks a lot @roji
Sam
@werebear73:matrix.org
[m]
Is this room for general questions or development discussions?
Sajan
@woodsongem
Hello All,
We have a function in PostgreSQL . which is a return customer details in table. how to call function from entity framework ?
Sam
@werebear73:matrix.org
[m]
I have done it with FromSqlRaw and FromSqlInterpolated but I haven't had any luck getting the result into an entity
Sergio Silveira
@RagingKore_twitter
Hi guys, thanks for the great tool. But I'm going nuts trying to use the BeginBinaryImportAsync to import an LTREE value. Can anyone help me out with this? (I have search issues, code etc without success)
Yadvaindera Sood
@ydsood

Hello - I am looking for a way to modify PostGreSql queries in C#.
Examples:
Select from Table 1 => Select from Table 1 where col2='value2'
Select from Table 1 where col1='value' => Select from Table 1 where col1='value' and col2='value2'

In order to accomplish this I need to be able to track locations for where clauses, from clauses etc. in complex queries. I can use a SqlParser for this but cannot find something for C#.
I want to use this class but it has been declared as internal.
https://github.com/npgsql/npgsql/blob/0d8dd34ae957e26c9e61edaa35219353b3b0bd8e/src/Npgsql/SqlQueryParser.cs#L51
The use case has been documented in the wiki here but there does not seem to be an existing parser exposed for npgsql.
https://wiki.postgresql.org/wiki/Query_Parsing

Anyone have any ideas on how to accomplish this?

Maulik Modi
@maulik-modi
@ydsood , what are the benefits you would get by doing this?
Björn Harrtell
@bjornharrtell
I use Npgsql, EFCore and NTS and when upgrading from .NET Core 3.1 to .NET 5.0 get into trouble with "Npgsql.PostgresException (0x80004005): 22023: Geometry has Z dimension but column does not". I've tried to tweak various settings but to no avail. Any ideas?
Björn Harrtell
@bjornharrtell
Narrowed it down to that it happens for geometries produced by WKTReader.. even if the input WKT has no third ordinate..
Venkat A
@avr2222
The type initializer for 'Npgsql.TypeMapping.GlobalTypeMapper' threw an exception.
i am getting this error any idea?
Alberto Passalacqua
@AlbertoPa
are you on net6 RC1?
Venkat A
@avr2222
I am able to resolve this by deploying system.text.json dll
ONoack
@ONoack

Hi i have a problem using the LTree Struct in .net 5, i am using the package Npgsql.EntityFrameworkCore.PostgreSQL, but i can not find the LTree struct anywhere like described in https://www.npgsql.org/efcore/api/Microsoft.EntityFrameworkCore.LTree.html

Also when trying to scaffold the database i get the following error: Could not find type mapping for column 'public.iam_permission.tree' with data type 'ltree'. Skipping column.

Anyone might can tell me what am i missing od doing wrong, really appreciated :)

Alberto Passalacqua
@AlbertoPa
not very specific to npg, but I am not sure where to ask: why does the EF doc on NRT say navigations should not be nullable? https://docs.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types#non-nullable-properties-and-initialization (purple box)? What would the downside be? They are null if Include is not used...
FerrariF70
@FerrariF70
Hello I using ef core and I configured ssl mode with certificate. How can I provided certificate from connection string or how I connection with ssl mode?
Shay Rojansky
@roji
@FerrariF70 check out the docs on connection string parameters: https://www.npgsql.org/doc/connection-string-parameters.html
@AlbertoPa the EF NRT docs don't say that navigations shouldn't be nullable in general; collection navigations should indeed never be nullable, since the absence of related entities is expressed via an empty list, rather than null. For reference (non-collection) navigations, if the navigation is optional (i.e. the foreign key is nullable in the database), then the navigation should also be nullable. If the navigation is required, it should probably be non-nullable (though see the difficulty with Include detailed in the docs)
@ONoack LTree support was only added to version 6.0 of the provider (see npgsql/efcore.pg#1592), are you using that?
Shay Rojansky
@roji
@bjornharrtell if you're still seeing the issue with NTS and EF Core 5.0, can you please open an issue with a code sample?
@ydsood Npgsql doesn't have a full SQL parser - there's a very light parser only to detect parameter placeholders and statement semicolon separators - so there's nothing there that could help you.
In general, the approach of parsing your SQL and modifying it is discouraged, as it's very brittle. Try seeing if you can produce the correct SQL in the first place.