Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
210 commits
Select commit Hold shift + click to select a range
e5c164f
Bring in conceptual docs
roji Sep 26, 2019
07d4313
Tiny grammar fix
roji Sep 26, 2019
fba4f3a
Move concurrency information from misc to modeling
roji Sep 30, 2019
ab6489e
Fix API naming changes in EFCore.PG 3.0.0
roji Sep 30, 2019
6880a57
Correct ASP.NET getting started instructions
roji Sep 30, 2019
86d7b66
Update to .NET Core 3.0
damageboy Oct 30, 2019
df5663f
Document array overlap & containment support
roji Nov 25, 2019
be91eaa
Tiny: add plus to version
roji Dec 28, 2019
3c29fd1
Add some nice tabs
roji Jan 6, 2020
5772816
Fix typo in configuration example
welteki Jan 7, 2020
09fecf5
Remove accidental text
roji Jan 7, 2020
cf600a7
Document identity sequence options
roji Jan 29, 2020
f54e74b
Update note on generated properties
roji Feb 14, 2020
42b1038
Remove empty line
roji Feb 14, 2020
6041f93
Fixed typo
sombraSoft Mar 5, 2020
4d57f3e
Add note on xmin as a shadow property
roji Mar 26, 2020
b6704d2
Fix headings in NTS page
roji Apr 24, 2020
573ac4b
Added example of `.Matches` taking a `ToTsQuery`
dharmaturtle Apr 25, 2020
c5a4757
Added `.OrderByDescending` `Rank` example
dharmaturtle Apr 26, 2020
3dc225c
Bump version of EFCore.PG in basic sample
roji May 13, 2020
b926e4a
Update badges
roji May 13, 2020
4b912c0
Correct JsonTypeof sample
roji May 25, 2020
1b60f38
Document collation and case sensitivity
roji Jun 11, 2020
6b3f89a
Fix code fragment
yakuri354 Jun 22, 2020
6fa3d98
Update full-text search docs
roji Feb 14, 2020
2f2e7cd
Note to call ReloadTypes after Migrate()
roji Jul 18, 2020
01255ba
Update concurrency.md
BorisWilhelms Sep 2, 2020
f576d0a
Add contibutors to the release notes
Brar Sep 2, 2020
7a2eb9e
Fix badge link
roji Sep 28, 2020
032acfc
Rename 3.0 release notes to 3.x
roji Sep 28, 2020
66f775c
Contribution info on EFCore.PG erroneously points to Npgsql
Brar Sep 28, 2020
898ab36
Minor grammar correction to caution message (#55)
sid-g Oct 8, 2020
c006b42
Various minor fixes to EFCore.PG docs
roji Oct 9, 2020
565d8f2
Redo docs on operation translation
roji Oct 9, 2020
dfb4d85
Add Guid.NewGuid
roji Oct 9, 2020
59ca253
Corrected some table titles
roji Oct 9, 2020
d20e493
Redo docs on operation translation (#57)
roji Oct 9, 2020
16ba554
Document unaccent
roji Oct 11, 2020
6b043a9
Various linter and formatting fixes
roji Oct 15, 2020
cc75b3f
Fix implicit and hidden system columns link in concurrency.md
jeremycook Oct 19, 2020
b3a1673
Some minor fixes
roji Oct 20, 2020
9071d5a
Adding more supported spatial operations (#67)
oshawa-connection Oct 25, 2020
44279d6
Release notes for the EFCore.PG 5.0 release
roji Oct 26, 2020
98d8e22
Correct mention
roji Oct 26, 2020
c81bbbc
Release notes for the EFCore.PG 5.0 release (#68)
roji Oct 26, 2020
15c17fb
Add "out of support" node under release notes
roji Oct 26, 2020
1c87f42
Fix JsonDocument usage docs
roji Oct 28, 2020
2ceeeb9
Add NodaTime improvements to EFCore.PG 5.0 release notes
roji Nov 9, 2020
6e0f43d
Update release notes for the 5.0 release
roji Nov 15, 2020
2141f0a
Postgres 12+ does not require trigger setup to update generated searc…
Nov 30, 2020
da4ce56
Minor typo fixes in code
Nov 30, 2020
daaf854
Add note on patching migrations for computed columns
roji Jan 5, 2021
522470b
Document Npgsql.EntityFrameworkCore.PostgreSQL.Trigrams
roji Jan 18, 2021
178c153
Document ltree support in EFCore.PG (#76)
roji Jan 31, 2021
63f61b4
Incorrect mapping for non-POCO Fluent example (#78)
Bouke Feb 15, 2021
edf25ba
EFCore.PG 6.0 breaking change note on arrays and value converters
roji Feb 19, 2021
a4a4469
Expression index requires v5 (not PG12) (#82)
Bouke Feb 22, 2021
20c160a
Add disposal information for JsonDocument
roji Mar 5, 2021
213a369
Fix typo (#94)
Bouke Apr 12, 2021
544b8b9
Add note on mapping enums with schemas in EF Core
roji Apr 14, 2021
4043c10
Update collations-and-case-sensitivity.md (#95)
addisonbeck Apr 14, 2021
84851af
Add some NTS translations
roji Apr 28, 2021
d225d6a
Correct property name in full text search docs
roji May 14, 2021
a519d12
Update array.md (#103)
FransBouma Jun 7, 2021
f6475ec
EF Core 6.0 release and breaking change notes (#116)
roji Sep 24, 2021
79a0f00
Fixup to EF Core release notes
roji Sep 24, 2021
cb93bf7
Correct TOC release notes link
roji Sep 24, 2021
aeeec19
Npgsql 6.0 release and breaking change notes (#117)
roji Sep 24, 2021
12b991e
Remove LegacyPostgis (#122)
roji Oct 5, 2021
0443e95
Add note on ltree support requiring PG13
roji Oct 5, 2021
5fce86a
Tweaks to timestamp release notes
roji Oct 5, 2021
08bbe8f
Remove some evil trailing whitespace
roji Oct 8, 2021
3c20ba6
Update date/time docs for 6.0 (#127)
roji Oct 11, 2021
ff2ca69
Document new 6.0 array translations (#123)
roji Oct 14, 2021
b3aab90
Add documentation on multiranges (#120)
roji Oct 14, 2021
3f795a7
Notes on date/time infinity conversions (#129)
roji Oct 15, 2021
fe7ce89
Document new timezone conversion translations (#134)
roji Oct 21, 2021
f858807
Document NodaTime timezone conversion translations (#135)
roji Oct 22, 2021
efd43be
Document full-text search translations (#136)
roji Oct 24, 2021
a31b5c7
Document DateTime.SpecifyKind translations (#142)
roji Oct 31, 2021
66e4679
Document NodaTime interval mapping (#144)
roji Nov 3, 2021
8c505db
Add docs on timestamp generation (#148)
roji Nov 8, 2021
daa4c3e
Release note on EF support for PG14 column compression (#141)
roji Nov 9, 2021
754bf0b
Add note on TimeZone in the date/time translations page
roji Nov 11, 2021
2775215
Add missing semicolon to SQL sample
roji Nov 13, 2021
4ac0823
Breaking change note on default mapping to multirange (#149)
roji Nov 14, 2021
d88575c
Document added translations on DateTimeOffset (#151)
roji Nov 22, 2021
8ae70a3
Tweaks to 6.0 timestamp breaking changes
roji Nov 25, 2021
0284ee1
Correct UseDatabaseTemplate method name (#153)
alewmt Nov 30, 2021
1a1207b
Update enum.md (#159)
NathanielBlack Dec 2, 2021
7c5421e
Added 6.0 breaking change note about Trigrams and FuzzyStringMatch (#…
roji Dec 9, 2021
5a2230f
Typo
roji Dec 13, 2021
8f7a0b3
Document random translation
roji Dec 18, 2021
81b80d3
Move EFCore.PG 2.1 to out of support
roji Dec 31, 2021
59f659e
Correct full-text search translations (#174)
roji Jan 11, 2022
0be6e2d
Add semicolon to TimeZone setting in migration
roji Jan 25, 2022
22cd22c
Document Total* members translation on TimeSpan (#178)
roji Jan 26, 2022
8bbd7ea
Add caution note for instance SSL callbacks (#186)
roji Feb 10, 2022
3b7fe39
Update ICU collations doc link
roji Feb 15, 2022
f01ae1d
Fix typo in json.md (#191)
Shaddix Feb 25, 2022
eeddae7
Add missing .HasMethod("GIN") in FTS example (#196)
PJB3005 Apr 7, 2022
061f5a3
Fix LTree translations (#198)
roji Apr 15, 2022
62ec955
Update 6.0.md (#200)
neokske Apr 19, 2022
a67d0b6
Update concurrency.md (#202)
JohnCgp Apr 22, 2022
5fd9206
Document obsoletion of EF default column collations (#203)
roji Apr 25, 2022
e39bcf9
Update enum docs to mention add support (#204)
Hoffs Apr 28, 2022
bbe473b
Some general tweaks and fixes (#206)
roji May 8, 2022
fe2cf93
Add note on wrapping scalars for JSON functions
roji May 17, 2022
92bffbb
Improve scalar wrapping note (#210)
NinoFloris May 19, 2022
7a1c769
Add JSON List.Count translation note
roji May 24, 2022
76c1de2
Add note on mapping enums with multiple context types
roji May 24, 2022
78e56dd
Correct GUID generation docs (#218)
roji Jun 30, 2022
6eb0878
Put quotes around enum labels in the ALTER TYPE statement (#227)
aradalvand Jul 27, 2022
9daa4b7
Add note on 6.0 timestamp migration and seeding (#230)
roji Aug 24, 2022
41cf05c
Document row value comparisons
roji May 8, 2022
af1d387
Document tsvector computed columns over JSON data
roji May 17, 2022
1562683
Document aggregate function translations
roji Jun 5, 2022
1fbab8d
Correct range aggregate translation docs (#232)
roji Aug 25, 2022
b5d0240
Pack of 7.0 doc changes
roji Oct 20, 2022
897724b
Markdownlint fixes
roji Oct 30, 2022
3569342
Document the new Microsoft.Extensions.Logging support (#255)
roji Nov 2, 2022
955c087
Document NpgsqlDataSource (#256)
roji Nov 3, 2022
1a0c0e3
Document NpgsqlDataSource (#256)
roji Nov 3, 2022
3184390
Placeholders for EFCore.PG 7.0 release notes
roji Nov 9, 2022
4aea15b
Complete EFCore.PG 7.0 release notes
roji Nov 10, 2022
6f7d0c9
Add toc link to EFCore.PG 7.0 release notes
roji Nov 10, 2022
b9b03eb
Move EFCore.PG 5.0 release notes to out of support
roji Nov 10, 2022
6bc26b4
Fix some broken links
roji Nov 14, 2022
e5c79ba
More link cleanup
roji Nov 14, 2022
6562da9
Remove "new and experimental" on the retrying strategy docs
roji Nov 16, 2022
024590b
Show GUID client-side gen for non-key properties
roji Nov 18, 2022
9cea7b0
Add 7.0 breaking change note for logging
roji Dec 8, 2022
546d9e3
Fix fixable warnings (#272)
Brar Dec 21, 2022
642c2ad
Fix build badge (#275)
vonzshik Dec 29, 2022
1d21365
Second attempt to fix badge (#276)
vonzshik Dec 29, 2022
4d9cd10
Fix badge links (#277)
vonzshik Jan 1, 2023
bfb3acc
.NET array indexing starts at zero
petergummer Jan 9, 2023
b6cc870
Fix cross-link
roji Jan 30, 2023
577dafd
Document new 8.0 array translations
roji May 22, 2023
1686239
Make markdownlint happy
roji May 22, 2023
c32f277
Fix typo in collations-and-case-sensitivity.md (#290)
meenzen Jun 12, 2023
1aa48f2
Update EFCore.PG docs for NpgsqlDataSource usage (#292)
roji Jun 14, 2023
0e2cff5
Enums types reload after migration fix. (#295)
toxsedyshev Jul 19, 2023
4855442
Document StringToArray
roji Feb 2, 2023
5ab3ad8
Tiny markdown fixes in translation docs (#302)
roji Sep 5, 2023
5d776b0
Fix incorrect Has/UseCollection
roji Sep 7, 2023
6b3ed36
Some release notes and breaking changes for 8.0 (#306)
roji Oct 11, 2023
cf1f68c
Document networking mapping changes (#307)
roji Oct 11, 2023
6e286a4
Documentation on storage parameters (#312)
roji Oct 28, 2023
d15a945
Tweak 8.0 "not-yet-ready" note
roji Oct 28, 2023
5556153
Document PG12->14 default compat mode breaking change (#313)
roji Nov 13, 2023
3abe623
Redo JSON documentation (#315)
roji Nov 19, 2023
ed1429e
EFCore.PG 8.0 release notes (#316)
roji Nov 19, 2023
23f1773
Document more breaking changes (#317)
roji Nov 19, 2023
f674310
Update notes to reflect that 8.0 was released
roji Nov 21, 2023
638ff72
Typo
roji Nov 21, 2023
af470e0
Add primitive collection context
roji Nov 21, 2023
9c1623a
Update contributors in release notes. (#321)
Brar Nov 21, 2023
d4def9c
Fix release tags in the thank you statements
Brar Nov 21, 2023
f29fad8
docs: Fix typo in JSON (#325)
ipostanogov Dec 7, 2023
9987db0
Escape pipes in string translations doc (#326)
haas-daniel Dec 8, 2023
dd68173
Update string.Contains() translation
roji May 11, 2024
f31e495
Docs related to version 7 GUID generation (#349)
roji Sep 1, 2024
81baa0c
Docs on the new enum/plugin config (#352)
roji Sep 13, 2024
028b943
Link to the 9.0 release notes
roji Sep 13, 2024
27217c5
Document new EF/Npgsql configuration experience (#353)
roji Sep 17, 2024
eb0443d
Bump docfx to 2.77.0 and adjust config (#357)
roji Sep 20, 2024
e0ca925
Replace c# code with csharp (#360)
vonzshik Sep 20, 2024
7144ae5
Remove gitter links
roji Sep 20, 2024
882ac40
Link to the 9.0 milestone issues
roji Sep 22, 2024
f622444
Correct JSON translation SQL
roji Sep 28, 2024
02e6a28
Document array_remove translation
roji Oct 26, 2024
723369a
Document DateOnly.DayNumber translations (#374)
roji Oct 28, 2024
bf3ba92
Add note on EFCore.PG jsonpath support
roji Oct 30, 2024
9ec3c1c
Some minor fixes to the EFCore.PG JSON page
roji Oct 30, 2024
9d92f05
Move 6.0 to "out of support" and some general minor changes for 9.0 (…
roji Nov 18, 2024
e9d1123
Some corrections regarding contributors for 9.0.0 (#384)
WhatzGames Dec 8, 2024
be4bcc5
Amend getting started example for externally provided NpgsqlDataSourc…
roji Jan 14, 2025
9eb6bb2
Fixed type name casing (#399)
YohDeadfall Mar 21, 2025
5bbe5e6
Document fuzzy text search translations (#405)
roji Apr 22, 2025
0d4895f
Add EFCore.PG 10 release notes plus other changes (#412)
roji Jul 7, 2025
348d0a9
Document translations for NodaTime LocalDate.{At,AtMidnight} (#413)
roji Jul 9, 2025
e841113
Fixup
roji Jul 9, 2025
d663a0c
Release notes and tweaks around EFCore.PG support for JSON (#420)
roji Oct 1, 2025
78261dd
Breaking change notes related to cidr (#421)
roji Oct 5, 2025
bd2e50e
Fix Typo (#422)
AmritD Oct 6, 2025
a65e770
Fix tab heading link for owned entities section (#423)
ryanspain Oct 16, 2025
1fa31f5
Work on Npgsql 10 breaking change notes (#425)
roji Oct 24, 2025
8ad7a1c
Cube docs
roji Nov 19, 2025
fe363f9
Add cube translation functions (#431)
kirkbrauer Nov 22, 2025
37a290d
Some more Npgsql 10 release note tweaks (#433)
roji Nov 22, 2025
fa97565
Document EFCore.PG 10 as released (#441)
roji Jan 2, 2026
bae92b9
Document temporal constraints (#444)
roji Jan 24, 2026
60de374
Document IntersectsBbox (#447)
roji Feb 2, 2026
31f9572
Document EFCore.PG targeting PostgreSQL version 16 by default (#454)
roji Mar 31, 2026
d5308b2
Document 10.0 array Contains breaking SQL translation change (#464)
roji Jul 2, 2026
dbd8e9e
Document explicit-source timezone conversion translation (#471)
roji Oct 12, 2026
90ba648
Document Daitch-Mokotoff translation (#472)
roji Oct 15, 2026
b0583ef
Document EF 11 JSON member indexes (#474)
roji Oct 16, 2026
ab85e5e
Document EFCore.PG 11 features and breaking changes (#475)
roji Oct 19, 2026
a9b12ba
Document EFCore.PG 11.0 improvements and translations (#476)
roji Oct 29, 2026
ea021c7
Update documentation for Npgsql 11.0 and EFCore.PG 11.0 (#481)
roji Nov 20, 2026
76a9d6d
Finalize the EFCore.PG 11.0 release notes (#482)
roji Nov 20, 2026
3bacff4
Document EF Core vector search (#484)
roji Nov 25, 2026
1de8315
Document EF Core regex translation limitations (#485)
roji Nov 25, 2026
8e55d9f
Import EFCore.PG conceptual documentation with history
roji Nov 26, 2026
29d1ede
Wire imported conceptual docs into documentation workflow
roji Nov 26, 2026
42bcaf2
Use GitHub App token for docs dispatch
roji Nov 26, 2026
86d3895
Point API reference TOC entry at generated namespace page
roji Nov 26, 2026
8966c3f
Restore source API TOC reference and remove obsolete doc trigger work…
roji Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This is the PostgreSQL provider for [Entity Framework Core](https://github.com/dotnet/efcore), built on top of [Npgsql](https://github.com/npgsql/npgsql). It translates EF Core LINQ queries into PostgreSQL SQL and handles PostgreSQL-specific features like arrays, JSON, ranges, full-text search, NodaTime, and PostGIS/NetTopologySuite.

Conceptual documentation lives in `docs/`. Update it as appropriate alongside code changes.

## Build and Test

Use the SDK pinned in `global.json` and dependency versions centralized in `Directory.Packages.props`. Consult EF APIs and test bases matching the pinned version; do not upgrade dependencies just to make a change compile.
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Documentation

on:
push:
branches: [main]
paths: ['docs/**']
pull_request:
paths: ['docs/**']

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Setup Node.js
uses: actions/setup-node@v7.0.0
with:
node-version: 24.x

- name: Run Markdownlint
run: |
npm i -g markdownlint-cli
markdownlint --config docs/.markdownlint.json "docs/**/*.md"

dispatch:
needs: lint
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'npgsql/efcore.pg'
runs-on: ubuntu-latest
steps:
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.DOCS_APP_ID }}
private-key: ${{ secrets.DOCS_APP_PRIVATE_KEY }}
owner: npgsql
repositories: doc

- name: Trigger documentation build
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: gh api --method POST repos/npgsql/doc/dispatches -f event_type=docs-changed
Comment thread
roji marked this conversation as resolved.
Resolved
25 changes: 0 additions & 25 deletions .github/workflows/trigger-doc-build.yml

This file was deleted.

16 changes: 16 additions & 0 deletions docs/.markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"default": true,
"MD011": false,
"MD013": false,
"MD024": false,
"MD028": false,
"MD033": { "allowed_elements": ["del", "a", "sup"] },
"MD051": false,
"MD046": {
"style": "fenced"
},
"MD055": false,
"MD056": false,
"MD059": false,
"MD060": false
}
168 changes: 168 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Npgsql Entity Framework Core Provider

[![stable](https://img.shields.io/nuget/v/Npgsql.EntityFrameworkCore.PostgreSQL.svg?label=stable)](https://www.nuget.org/packages/Npgsql.EntityFrameworkCore.PostgreSQL/)
[![next patch](https://img.shields.io/myget/npgsql/v/Npgsql.EntityFrameworkCore.PostgreSQL.svg?label=next%20patch)](https://www.myget.org/feed/npgsql/package/nuget/Npgsql.EntityFrameworkCore.PostgreSQL)
[![vnext](https://img.shields.io/myget/npgsql-vnext/vpre/Npgsql.EntityFrameworkCore.PostgreSQL.svg?label=vnext)](https://www.myget.org/feed/npgsql-vnext/package/nuget/Npgsql.EntityFrameworkCore.PostgreSQL)
[![build](https://img.shields.io/github/actions/workflow/status/npgsql/efcore.pg/build.yml?branch=main)](https://github.com/npgsql/efcore.pg/actions)

Npgsql has an Entity Framework (EF) Core provider. It behaves like other EF Core providers (e.g. SQL Server), so the [general EF Core docs](https://docs.microsoft.com/ef/core/index) apply here as well. If you're just getting started with EF Core, those docs are the best place to start.

Development happens in the [Npgsql.EntityFrameworkCore.PostgreSQL](https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL) repository, all issues should be reported there.

## Configuring the project file

To use the Npgsql EF Core provider, add a dependency on `Npgsql.EntityFrameworkCore.PostgreSQL`. You can follow the instructions in the general [EF Core Getting Started docs](https://docs.microsoft.com/ef/core/get-started/).

Below is a `.csproj` file for a console application that uses the Npgsql EF Core provider:

```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
</ItemGroup>
</Project>
```

## Defining a model and a `DbContext`

Let's say you want to store blogs and their posts in their database; you can model these as .NET types as follows:

```csharp
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }

public List<Post> Posts { get; set; }
}

public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }

public int BlogId { get; set; }
public Blog Blog { get; set; }
}
```

You then define a `DbContext` type which you'll use to interact with the database:

### [OnConfiguring](#tab/onconfiguring)

Using `OnConfiguring()` to configure your context is the easiest way to get started, but is discouraged for most production applications:

```csharp
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseNpgsql("<connection string>");
}

// At the point where you need to perform a database operation:
using var context = new BloggingContext();
// Use the context...
```

### [DbContext pooling](#tab/context-pooling)

```csharp
var dbContextFactory = new PooledDbContextFactory<BloggingContext>(
new DbContextOptionsBuilder<BloggingContext>()
.UseNpgsql("<connection string>")
.Options);

// At the point where you need to perform a database operation:
using var context = dbContextFactory.CreateDbContext();
// Use the context...
```

### [ASP.NET / DI](#tab/aspnet)

When using ASP.NET - or any application with dependency injection - the context instance will be injected into your code. Use the following to configure EF with your DI container:

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDbContextPool<BloggingContext>(opt =>
opt.UseNpgsql(builder.Configuration.GetConnectionString("BloggingContext")));

public class BloggingContext(DbContextOptions<BloggingContext> options) : DbContext(options)
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}
```

***

For more information on getting started with EF, consult the [EF getting started documentation](https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=netcore-cli).

## Additional Npgsql configuration

The Npgsql EF provider is built on top of the lower-level Npgsql ADO.NET provider ([docs](https://www.npgsql.org/doc/index.html)); these two separate components support various options you may want to configure.

If you're using EF 9.0 or above, the `UseNpgsql()` is a single point where you can configure everything related to Npgsql. For example:

```csharp
builder.Services.AddDbContextPool<BloggingContext>(opt =>
opt.UseNpgsql(
builder.Configuration.GetConnectionString("BloggingContext"),
o => o
.SetPostgresVersion(13, 0)
.UseNodaTime()
.MapEnum<Mood>("mood")));
```

The above configures the EF provider to produce SQL for PostgreSQL version 13 (avoiding newer incompatible features), adds a plugin allowing use of NodaTime for date/time type mapping, and maps a .NET enum type. Note that the last two also require configuration at the lower-level ADO.NET layer, which the code above does for you automatically.

If you need to configure something at the lower-level ADO.NET layer, use `ConfigureDataSource()` as follows:

```csharp
builder.Services.AddDbContextPool<BloggingContext>(opt =>
opt.UseNpgsql(
builder.Configuration.GetConnectionString("BloggingContext"),
o => o.ConfigureDataSource(dataSourceBuilder => dataSourceBuilder.UseClientCertificate(certificate))));
```

`ConfigureDataSource()` provides access to a lower-level [`NpgsqlDataSourceBuilder`](/doc/basic-usage.html#data-source) which you can use to configure all aspects of the Npgsql ADO.NET provider.

> [!WARNING]
> The EF provider internally creates an NpgsqlDataSource and uses that; for most configuration (e.g. connection string), the provider knows to switch between NpgsqlDataSources automatically.
> However, it's not possible to detect configuration differences within the `ConfigureDataSource()`; as a result, avoid performing varying configuration inside `ConfigureDataSource()`, since you may
> get the wrong NpgsqlDataSource. If you find yourself needing to vary Npgsql ADO.NET configuration, create an external NpgsqlDataSource yourself with the desired configuration and pass that to
> `UseNpgsql()` as described below.

### Using an external NpgsqlDataSource

If you're using a version of EF prior to 9.0, the above configuration methods aren't available. You can still create an NpgsqlDataSource yourself, and then pass it to EF's `UseNpgsql()`:

```csharp
var dataSourceBuilder = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("BloggingContext"));
dataSourceBuilder.MapEnum<Mood>();
dataSourceBuilder.UseNodaTime();
var dataSource = dataSourceBuilder.Build();

builder.Services.AddDbContextPool<BloggingContext>(opt => opt
.UseNpgsql(dataSource, o => o
.SetPostgresVersion(13, 0)
.UseNodaTime()
.MapEnum<Mood>("mood")));
```

Note that when using an external NpgsqlDataSource, you need to configure mappings and plugins at both levels yourself - both on the NpgsqlDataSource and at the EF provider level.

## Using an Existing Database (Database-First)

The Npgsql EF Core provider also supports reverse-engineering a code model from an existing PostgreSQL database ("database-first"). To do so, use dotnet CLI to execute the following:

```bash
dotnet ef dbcontext scaffold "Host=my_host;Database=my_db;Username=my_user;Password=my_pw" Npgsql.EntityFrameworkCore.PostgreSQL
```
54 changes: 54 additions & 0 deletions docs/mapping/array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Array Type Mapping

PostgreSQL has the unique feature of supporting [*array data types*](https://www.postgresql.org/docs/current/static/arrays.html). This allow you to conveniently and efficiently store several values in a single column, where in other database you'd typically resort to concatenating the values in a string or defining another table with a one-to-many relationship.

> [!NOTE]
> Although PostgreSQL supports multidimensional arrays, these aren't yet supported by the EF Core provider.

## Mapping arrays

Simply define a regular .NET array or `List<>` property:

```csharp
public class Post
{
public int Id { get; set; }
public string Name { get; set; }
public string[] Tags { get; set; }
public List<string> AlternativeTags { get; set; }
}
```

The provider will create `text[]` columns for the above two properties, and will properly detect changes in them - if you load an array and change one of its elements, calling `SaveChanges` will automatically update the row in the database accordingly.

## Operation translation

The provider can also translate CLR array operations to the corresponding SQL operation; this allows you to efficiently work with arrays by evaluating operations in the database and avoids pulling all the data. The following table lists the range operations that currently get translated; all these translations work both for .NET arrays (`int[]`) and for generic Lists (`List<int>`). If you run into a missing operation, please open an issue.

.NET | SQL | Notes
--------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----
array[0] | [array\[1\]](https://www.postgresql.org/docs/current/arrays.html#ARRAYS-ACCESSING) |
array.Length / list.Count | [cardinality(array)](https://www.postgresql.org/docs/current/static/functions-array.html#ARRAY-FUNCTIONS-TABLE) |
array.Skip(2) | [array\[3,\]](https://www.postgresql.org/docs/current/arrays.html#ARRAYS-ACCESSING) | Added in 8.0
array.Take(2) | [array\[,2\]](https://www.postgresql.org/docs/current/arrays.html#ARRAYS-ACCESSING) | Added in 8.0
array.Skip(1).Take(2) | [array\[2,3\]](https://www.postgresql.org/docs/current/arrays.html#ARRAYS-ACCESSING) | Added in 8.0
array1 == array2 | [array1 = array2](https://www.postgresql.org/docs/current/static/arrays.html) |
array1.SequenceEqual(array2) | [array1 = array2](https://www.postgresql.org/docs/current/static/arrays.html) |
array1.Take(2).SequenceEqual(array2) | [array1\[:2\] = array2](https://www.postgresql.org/docs/current/arrays.html#ARRAYS-ACCESSING) | Added in 11.0; also supports Skip() and Skip().Take()
arrayNonColumn.Contains(element) | [element = ANY(arrayNonColumn)](https://www.postgresql.org/docs/current/static/functions-comparisons.html#AEN21104) | Can use regular index
arrayColumn.Contains(element) | [arrayColumn @> ARRAY\[element\]](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-OPERATORS-TABLE) | Can use GIN index
array.Append(element) | [array_append(array, element)](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE) | Added in 6.0
array.Where(i => i != 8) | [array_remove(array, value)](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE) | Added in 9.0
array1.Concat(array2) | [array1 \|\| array2](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE) | Added in 6.0
array.IndexOf(element) | [array_position(array, element) - 1](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE) | Added in 6.0
array.IndexOf(element, startIndex) | [array_position(array, element, startIndex + 1) - 1](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE) | Added in 6.0
String.Join(separator, array) | [array_to_string(array, separator, '')](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE) | Added in 6.0
array.Any() | [cardinality(array) > 0](https://www.postgresql.org/docs/current/static/functions-array.html#ARRAY-FUNCTIONS-TABLE) |
array1.Intersect(array2).Any() | [array1 && array2](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-OPERATORS-TABLE) | Added in 8.0
array1.Any(i => array2.Contains(i)) | [array1 && array2](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-OPERATORS-TABLE) |
array1.All(i => array2.Contains(i)) | [array1 <@ array2](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-OPERATORS-TABLE) |
array.Any(s => EF.Functions.Like(string, s)) | [string LIKE ANY (array)](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.30.16) |
array.Any(s => EF.Functions.ILike(string, s)) | [string ILIKE ANY (array)](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.30.16) |
array.All(s => EF.Functions.Like(string, s)) | [string LIKE ALL (array)](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.30.16) |
array.All(s => EF.Functions.ILike(string, s)) | [string ILIKE ALL (array)](https://www.postgresql.org/docs/current/functions-comparisons.html#id-1.5.8.30.16) |
EF.Functions.ArrayAgg(values) | [array_agg(values)](https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-AGGREGATE-TABLE) | Added in 7.0, See [Aggregate functions](translations.md#aggregate-functions).
Loading
Loading