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