LINQPad PostgreSQL Driver
This is a driver for LINQPad to add support for PostgreSQL databases. This driver uses LINQ to DB to execute the LINQ queries and Npgsql for the database access. In addition Dapper is used for a more convenient database access during the model creation.
- Download the
.lpxfile of the latest release from the releases tab (e.g.
- Run LINQPad and click Add connection.
- Click View more drivers.
- Click Browse and select the
.lpxfile. The driver has now been installed.
- The driver (PostgreSQL (LINQ to DB)) should now show up in the Add connection dialog.
Setting up a connection
- Click Add connection, select the driver and click Next.
- Provide the connection info by either specifying the server (e.g.
localhost:5432) and database (with optional username and password) or by specifying a Npgsql connection string manually. If you do not specify a port explicitly the default port
- Create the connection by clicking the Save button.
Unfortunately, editing data directly in the results grid is not supported for third-party drivers. You can, however, use the LINQ to DB
DataConnection to modify your data. The
DataConnection can be accessed using the
this keyword in your query. In the following some samples to insert, update and delete records are provided. You can get more detailed information on the LINQ to DB website.
If you want to provide an ID yourself:
var user = new User(); user.Id = 42; user.Name = "John Doe"; user.Emailaddress = "email@example.com"; this.Insert(user);
If the ID is generated by the database:
var user = new User(); user.Name = "John Doe"; user.Emailaddress = "firstname.lastname@example.org"; var userId = this.InsertWithIdentity(user);
If you have an instance of the object you want to update:
var user = Users.Single(u => u.Id == 42); user.Emailaddress = "email@example.com"; this.Update(user);
If you want to update all records matching certain criteria:
Users.Where(u => u.Id == 42) .Set(u => u.Emailaddress, "firstname.lastname@example.org") .Update();
If you have an instance of the object you want to delete:
var user = Users.Single(u => u.Id == 42); this.Delete(user);
If you want to delete all records matching certain criteria:
Users.Delete(u => u.Id == 42);