LINQPad PostgreSQL Driver
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DynamicLinqPadPostgreSqlDriver.Shared
DynamicLinqPadPostgreSqlDriver.Tests
DynamicLinqPadPostgreSqlDriver.UI
DynamicLinqPadPostgreSqlDriver
.gitignore
DynamicLinqPadPostgreSqlDriver.sln
LICENSE
README.md
VersionInfo.cs

README.md

LINQPad PostgreSQL Driver

Build status

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.

This driver has been tested with PostgreSQL 9.4.4 but should work with all versions supported by LINQ to DB v1.0.7.4 and Npgsql v3.0.7. It can be used with LINQPad versions 4 and 5.

Installation

  1. Download the .lpx file of the latest release from the releases tab (e.g. LINQPad.PostgreSQL.Driver.0.1.2.lpx).
  2. Run LINQPad and click Add connection.
  3. Click View more drivers.
  4. Click Browse and select the .lpx file. The driver has now been installed.
  5. The driver (PostgreSQL (LINQ to DB)) should now show up in the Add connection dialog.

Setting up a connection

  1. Click Add connection, select the driver and click Next.
  2. 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 5432 is used.
  3. Create the connection by clicking the Save button.

Modifying data

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.

Insert

If you want to provide an ID yourself:

var user = new User();
user.Id = 42;
user.Name = "John Doe";
user.Emailaddress = "john.doe@xyz.com";

this.Insert(user);

If the ID is generated by the database:

var user = new User();
user.Name = "John Doe";
user.Emailaddress = "john.doe@xyz.com";

var userId = this.InsertWithIdentity(user);

Update

If you have an instance of the object you want to update:

var user = Users.Single(u => u.Id == 42);
user.Emailaddress = "john.doe@abc.com";

this.Update(user);

If you want to update all records matching certain criteria:

Users.Where(u => u.Id == 42)
	 .Set(u => u.Emailaddress, "john.doe@abc.com")
	 .Update();

Delete

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);