npgsql | Npgsql is the .NET data provider for PostgreSQL | SQL Database library
kandi X-RAY | npgsql Summary
kandi X-RAY | npgsql Summary
Npgsql is the open source .NET data provider for PostgreSQL. It allows you to connect and interact with PostgreSQL server using .NET. For the full documentation, please visit the Npgsql website. For the Entity Framework Core provider that works with this provider, see Npgsql.EntityFrameworkCore.PostgreSQL.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of npgsql
npgsql Key Features
npgsql Examples and Code Snippets
Community Discussions
Trending Discussions on npgsql
QUESTION
Table mytable
may have 0 .. 150000 rows in different databases.
How to determine whether it has more than approximately 100 rows rapidly?
It looks like this query:
...ANSWER
Answered 2022-Apr-14 at 22:40How to determine whether it has more than approximately 100 rows rapidly?
Perfect solution for just that:
QUESTION
I migrate an ASP.NET Core project from 3.1 to 6.0.
I have copied old migration and pasted it to our new version
Migration on EF Core 3.1 (old)
...ANSWER
Answered 2022-Mar-20 at 14:18EF Core 6 Npgsql has introduced some breaking changes to timestamp handling logic. You can try to "revert" back to old behaviour by adding next line either to Startup
or Program
file:
QUESTION
I'm struggling to add an enum to a where
condition I have on my queries.
I have the following definition for my class:
...ANSWER
Answered 2021-Nov-16 at 20:05It seems like this is an issue in the PostgreSQL EF Core provider.
The following workaround should solve it, but there are version limitations; See notes below.
Map:
QUESTION
I'm trying to Deploy .Net 6 app with multiple projects to Linux Elastic Beanstalk Server from mac development machine. I'm having trouble querying the api after it has been deployed. I've done it in 2 ways - Just an EC2 instance by following this tutorial, just using command line, and through Elastic beanstalk console. So I have 2 EC2 instances. They both say they are running.
The project has one Asp.Net app (Vepo.Web) and 5 helper projects for the app layers. the "Vepo" project is just a placeholder I made because the internet told me there is a bug when you name your dll different to your solution; and the solution is "Vepo.sln".
The files created by the publish look like this:
I got the source code to deploy by cd into my asp.net core web app (Vepo.Web), then run dotnet publish -r linux-x64 --self-contained false --output build
, then go to "Vepo.Web/build" in finder. Then select all files > right-click > compress (do not compress the parent folder!). That creates "archive.zip". Then upload "archive.zip" in the Elastic Beanstalk Console. And now it looks like this:
But I don't seem to be able to query the api. In Postman I'm trying:
ec2-54-xxx-xxx-95.ap-southeast-2.compute.amazonaws.com:5001/Users
but I get:
Error: connect ECONNREFUSED 54.xxx.xxx.95:5000
And navigating to it gives me:
I have created these inbound rules to allow anyone in because I'm desperately trying to get in:
Can someone help me be able to hit endpoints in my web API without getting 404/401? I will give any information required if I'm missing something.
UPDATE: I guess the app is running when I ssh into it and run this command (no idea how to access it from postman or my app, going to this in the browser does not work https://ec2-54-xxx-xxx-53.ap-southeast-2.compute.amazonaws.com:5001/fashionitems/search?searchTerm=B¤tPage=1&pageSize=10):
...ANSWER
Answered 2022-Mar-02 at 10:43The answer basically try summarizing the different comments posted in the question.
The problem can be motivated for many different reasons.
The most important thing to keep in mind is that EB provides a nginx proxy for serving the application.
By default this proxy expects your application to listen on port 5000
.
According to the logs you provided, the application seems to start properly and it successfully connect to the database.
As you pointed out, it reports that the application is listening on http://localhost:5000
: it may not be a problem, but perhaps your application is listening only in a certain network interface/address.
Just to be sure, and in fact, at the end it seems to be the solution, configure your application Kestrel server to listen on the mask http://*:5000
, using .UseUrls("http://*:5000")
in your Startup
class, for instance. This article provides several different options for configuring where the application should listen to.
QUESTION
So I'm running into a rather odd issue here. I've got a PostgreSQL 14 server and I'm using the Npgsql Entity Framework Core provider to access it. If I have an Entity Framework Core entity that contains a date as a NodaTime Instant
type (which becomes timestamp with time zone
in the database) and try to project that via .InZone(timeZone).LocalDateTime
, I run into 3 situations.
Actual example query would be something like this:
...ANSWER
Answered 2022-Feb-25 at 21:53The NodaTime plugin doesn't support passing parameterized time zones from .NET; you can only use a constant expression such as DateTimeZoneProviders.Tzdb["Europe/Berlin"]
(see these docs for supported translations). You can use this to convert a PG timestamp with time zone
into a timestamp without time zone
in PG, and then retrieve the result as a timestamp without time zone
, which can be read as a NodaTime LocalDateTime.
However, if what you're looking for is to get a ZonedDateTime/LocalDateTime with the time zone of the client machine (where .NET is executing), then doing .InUtc().LocalDateTime
is the way to do that - any reason you're trying to avoid it?
A bit more context (as well as a full code sample) could shed some more light on what you're trying to achieve.
QUESTION
I'm trying to create a docker-compose script to fire a stack with a PostgreSql database and an ASP.NET Core 6 Web API. To test the scenario, I've created a new ASP.NET Core 6 Web API using the default template. I have then added NuGet package Npgsql
(6.0.3), and a sample controller which just queries the DB engine version, e.g.:
ANSWER
Answered 2022-Feb-22 at 16:23When a container connects to another container on the bridge network, you use the container port. Not the mapped port on the host. So your connection string should be
QUESTION
I'm using ASP.NET Core 6 MVC to create an app linked to a database and I have an issue :
I scaffolded a controller and its views (create, edit...) but when I try to create an object to send to db with Entity Framework, the DateOnly
typed fields won't work and put in this date for all dates I try to write : 292269055-12-03 (it seems to be the max value ?).
I need to use DateOnly
type for compatibility reasons because the database has date
columns (I found this information here https://www.npgsql.org/doc/types/datetime.html) and if I try to use datetime
, it doesn't work.
There is my code :
View :
...ANSWER
Answered 2021-Nov-18 at 15:43I have no experience yet with .NET 6, but I did some research about this. https://devblogs.microsoft.com/dotnet/date-time-and-time-zone-enhancements-in-net-6/
And I found next line
QUESTION
I have a problem when I SetCommandTimeout is like the method is not working properly.
I Use PostgreSQL as database, and for the EntityFramework Core I'm using Npgsql.EntityFrameworkCore.PostgreSQL
with Version 5.0.5.1
In the code I Set Timeout for 1s like this context.Database.SetCommandTimeout(1);
and I set a Stopwatch to check how much time it takes, but the ElapsedMiliseconds always return around 15000ms to 16000ms. so the SetCommandTimeout(1)
is clearly not working.
I also tried using context.Database.SetCommandTimeout(TimeSpan.FromSeconds(1));
is not working either.
One more thing, I only want to Set Timeout for specific Request. So the other Request will have the default timeout.
Here's my code:
...ANSWER
Answered 2022-Jan-26 at 07:15The command timeout is the time a query / command is allowed to execute on the database server. The timer starts when the database server receives the request. Your end-to-end round trip time may be higher than the command timeout due to network throughput or other constraints - including resource exhaustion on your web server.
Command Timeout: The time to wait (in seconds) while trying to execute a command before terminating the attempt and generating an error. Source
QUESTION
...Maybe using TFactory in AddDbContextFactory
in EF Core extensions?
I've only seen AddDbContextFactory examples being used with just the TContext generic. They're always very explicit to say you have to use a using statement.
In similar situations (when I useClass in Angular or AddScoped in .NET Core), I make the variable I want to see in a constructor the first generic argument and the second generic argument what actually gets injected. You know, like:
...ANSWER
Answered 2022-Jan-20 at 18:39Dependency inject the concrete class. create a factory to select the subclass by type. Create a parent class with a private DbContext _dbContext. Inherit the subclass from the parent class and call the parent class constructor with :base(dbContext) of the subclass. The parent class can now access in its methods the subclass context. The subclass can share the methods of the parent class for (add, select, update, and deleting by set the data context of the subclass). the subclass will dependency inject the specific dbcontext in its constructor and set the parent class dbcontext variable in its constructor. the subclass repository class can then access the base class methods within its body.
in startup define the subclass repository pattern
in public void ConfigureServices(IServiceCollection services)
QUESTION
I use Postgres and I have DB with a table that looks like that
...ANSWER
Answered 2022-Jan-14 at 20:20npgsql driver uses System.Text.Json
for serializing json
values. So all you need is to annotate your property with JsonPropertyName
attribute.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install npgsql
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page