Skip to content

Commit f0b189d

Browse files
authored
Replace c# code with csharp (#360)
1 parent 16b8878 commit f0b189d

48 files changed

Lines changed: 213 additions & 213 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

conceptual/EF6.PG/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Example use cases:
144144
- Preventing accidental insertion of DateTime values having ```DateTimeKind.Unspecified```.
145145
- Forcing all postgres date/time types to be returned to Entity Framework as ```DateTimeOffset```.
146146

147-
```c#
147+
```csharp
148148
[DbConfigurationType(typeof(AppDbContextConfiguration))]
149149
public class AppDbContext : DbContext
150150
{

conceptual/EFCore.PG/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Below is a `.csproj` file for a console application that uses the Npgsql EF Core
3131

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

34-
```c#
34+
```csharp
3535
public class Blog
3636
{
3737
public int BlogId { get; set; }
@@ -57,7 +57,7 @@ You then define a `DbContext` type which you'll use to interact with the databas
5757

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

60-
```c#
60+
```csharp
6161
public class BloggingContext : DbContext
6262
{
6363
public DbSet<Blog> Blogs { get; set; }
@@ -74,7 +74,7 @@ using var context = new BloggingContext();
7474

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

77-
```c#
77+
```csharp
7878
var dbContextFactory = new PooledDbContextFactory<BloggingContext>(
7979
new DbContextOptionsBuilder<BloggingContext>()
8080
.UseNpgsql("<connection string>")
@@ -89,7 +89,7 @@ using var context = dbContextFactory.CreateDbContext();
8989

9090
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:
9191

92-
```c#
92+
```csharp
9393
var builder = WebApplication.CreateBuilder(args);
9494

9595
builder.Services.AddDbContextPool<BloggingContext>(opt =>
@@ -112,7 +112,7 @@ The Npgsql EF provider is built on top of the lower-level Npgsql ADO.NET provide
112112

113113
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:
114114

115-
```c#
115+
```csharp
116116
builder.Services.AddDbContextPool<BloggingContext>(opt =>
117117
opt.UseNpgsql(
118118
builder.Configuration.GetConnectionString("BloggingContext"),
@@ -126,7 +126,7 @@ The above configures the EF provider to produce SQL for PostgreSQL version 13 (a
126126

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

129-
```c#
129+
```csharp
130130
builder.Services.AddDbContextPool<BloggingContext>(opt =>
131131
opt.UseNpgsql(
132132
builder.Configuration.GetConnectionString("BloggingContext"),
@@ -145,7 +145,7 @@ builder.Services.AddDbContextPool<BloggingContext>(opt =>
145145

146146
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 EF's `UseNpgsql()`:
147147

148-
```c#
148+
```csharp
149149
var dataSourceBuilder = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("BloggingContext"));
150150
dataSourceBuilder.MapEnum<Mood>();
151151
dataSourceBuilder.UseNodaTime();

conceptual/EFCore.PG/mapping/array.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PostgreSQL has the unique feature of supporting [*array data types*](https://www
99

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

12-
```c#
12+
```csharp
1313
public class Post
1414
{
1515
public int Id { get; set; }

conceptual/EFCore.PG/mapping/enum.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you're using EF 9.0 or above, simply call `MapEnum` inside your `UseNpgsql` i
1515

1616
If you're passing a connection string to `UseNpgsql`, simply add the `MapEnum` call as follows:
1717

18-
```c#
18+
```csharp
1919
builder.Services.AddDbContext<MyContext>(options => options.UseNpgsql(
2020
"<connection string>",
2121
o => o.MapEnum<Mood>("mood")));
@@ -27,7 +27,7 @@ This configures all aspects of Npgsql to use your `Mood` enum - both at the EF a
2727

2828
If you're creating an external NpgsqlDataSource and passing it to `UseNpgsql`, you must make sure to map your enum on that data independently of the EF-level setup:
2929

30-
```c#
30+
```csharp
3131
var dataSourceBuilder = new NpgsqlDataSourceBuilder("<connection string>");
3232
dataSourceBuilder.MapEnum<Mood>();
3333
var dataSource = dataSourceBuilder.Build();
@@ -47,7 +47,7 @@ On versions of EF prior to 9.0, enum setup is more involved and consists of seve
4747

4848
First, you must specify the PostgreSQL enum type on your model, just like you would with tables, sequences or other databases objects:
4949

50-
```c#
50+
```csharp
5151
protected override void OnModelCreating(ModelBuilder builder)
5252
=> builder.HasPostgresEnum<Mood>();
5353
```
@@ -62,7 +62,7 @@ Even if your database enum is created, Npgsql has to know about it, and especial
6262

6363
Since version 7.0, NpgsqlDataSource is the recommended way to use Npgsql. When using NpgsqlDataSource, map your enum when building your data source:
6464

65-
```c#
65+
```csharp
6666
// Call MapEnum() when building your data source:
6767
var dataSourceBuilder = new NpgsqlDataSourceBuilder(/* connection string */);
6868
dataSourceBuilder.MapEnum<Mood>();
@@ -75,7 +75,7 @@ builder.Services.AddDbContext<MyContext>(options => options.UseNpgsql(dataSource
7575

7676
Since version 7.0, NpgsqlDataSource is the recommended way to use Npgsql. However, if you're not yet using NpgsqlDataSource, map enums by adding the following code, *before* any EF Core operations take place. An appropriate place for this is in the static constructor on your DbContext class:
7777

78-
```c#
78+
```csharp
7979
static MyDbContext()
8080
=> NpgsqlConnection.GlobalTypeMapper.MapEnum<Mood>();
8181
```
@@ -91,7 +91,7 @@ This code lets Npgsql know that your CLR enum type, `Mood`, should be mapped to
9191

9292
Once your enum is properly set up with EF, you can use your CLR enum type just like any other property:
9393

94-
```c#
94+
```csharp
9595
public class Blog
9696
{
9797
public int Id { get; set; }
@@ -113,7 +113,7 @@ using (var ctx = new MyDbContext())
113113

114114
The Npgsql provider only allow adding new values to existing enums, and the appropriate migrations will be automatically created as you add values to your CLR enum type. However, PostgreSQL itself doesn't support removing enum values (since these may be in use), and while renaming values is supported, it isn't automatically done by the provider to avoid using unreliable detection heuristics. Renaming an enum value can be done by including [raw SQL](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#arbitrary-changes-via-raw-sql) in your migrations as follows:
115115

116-
```c#
116+
```csharp
117117
migrationBuilder.Sql("ALTER TYPE mood RENAME VALUE 'happy' TO 'thrilled';");
118118
```
119119

conceptual/EFCore.PG/mapping/full-text-search.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PostgreSQL has [built-in support for full-text search](https://www.postgresql.or
66

77
PostgreSQL full text search types are mapped onto .NET types built-in to Npgsql. The `tsvector` type is mapped to `NpgsqlTsVector` and `tsquery` is mapped to `NpgsqlTsQuery`. This means you can use properties of type `NpgsqlTsVector` directly in your model to create `tsvector` columns. The `NpgsqlTsQuery` type on the other hand, is used in LINQ queries.
88

9-
```c#
9+
```csharp
1010
public class Product
1111
{
1212
public int Id { get; set; }
@@ -24,7 +24,7 @@ public class Product
2424

2525
This method adds a `tsvector` column to your table, that is automatically updated when the row is modified. First, add an `NpgsqlTsVector` property to your entity:
2626

27-
```c#
27+
```csharp
2828
public class Product
2929
{
3030
public int Id { get; set; }
@@ -43,7 +43,7 @@ Setting up the column to be auto-updated depends on your PostgreSQL version. On
4343
4444
The following will set up a generated `tsvector` column, over which you can easily create an index:
4545

46-
```c#
46+
```csharp
4747
protected override void OnModelCreating(ModelBuilder modelBuilder)
4848
{
4949
modelBuilder.Entity<Product>()
@@ -60,7 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6060

6161
First, modify the `OnModelCreating()` of your context class to add an index as follows:
6262

63-
```c#
63+
```csharp
6464
protected override void OnModelCreating(ModelBuilder modelBuilder)
6565
{
6666
modelBuilder.Entity<Product>()
@@ -71,7 +71,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
7171

7272
Now generate a migration (`dotnet ef migrations add ....`), and open it with your favorite editor, adding the following:
7373

74-
```c#
74+
```csharp
7575
public partial class CreateProductTable : Migration
7676
{
7777
protected override void Up(MigrationBuilder migrationBuilder)
@@ -99,7 +99,7 @@ public partial class CreateProductTable : Migration
9999

100100
Once your auto-updated `tsvector` column is set up, any inserts or updates on the `Products` table will now update the `SearchVector` column and maintain it automatically. You can query it as follows:
101101

102-
```c#
102+
```csharp
103103
var context = new ProductDbContext();
104104
var npgsql = context.Products
105105
.Where(p => p.SearchVector.Matches("Npgsql"))
@@ -112,7 +112,7 @@ Version 5.0.0 of the provider includes sugar for defining the appropriate expres
112112

113113
#### [Version 5.0.0](#tab/v5)
114114

115-
```c#
115+
```csharp
116116
modelBuilder.Entity<Blog>()
117117
.HasIndex(b => new { b.Title, b.Description })
118118
.HasMethod("GIN")
@@ -123,7 +123,7 @@ modelBuilder.Entity<Blog>()
123123

124124
Create a migration which will contain the index creation SQL (`dotnet ef migrations add ...`). At this point, open the generated migration with your editor and add the following:
125125

126-
```c#
126+
```csharp
127127
protected override void Up(MigrationBuilder migrationBuilder)
128128
{
129129
migrationBuilder.Sql(@"CREATE INDEX fts_idx ON ""Product"" USING GIN (to_tsvector('english', ""Name"" || ' ' || ""Description""));");
@@ -138,7 +138,7 @@ protected override void Down(MigrationBuilder migrationBuilder)
138138

139139
Once the index is created on the `Title` and `Description` columns, you can query as follows:
140140

141-
```c#
141+
```csharp
142142
var context = new ProductDbContext();
143143
var npgsql = context.Products
144144
.Where(p => EF.Functions.ToTsVector("english", p.Title + " " + p.Description)

conceptual/EFCore.PG/mapping/general.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The EF Core provider transparently maps the types supported by Npgsql at the ADO
44

55
This means that you can use PostgreSQL-specific types, such as `inet` or `circle`, directly in your entities. Simply define your properties just as if they were a simple type, such as a `string`:
66

7-
```c#
7+
```csharp
88
public class MyEntity
99
{
1010
public int Id { get; set; }
@@ -25,14 +25,14 @@ In some cases, your .NET property type can be mapped to several PostgreSQL data
2525

2626
## [Data Annotations](#tab/data-annotations)
2727

28-
```c#
28+
```csharp
2929
[Column(TypeName="jsonb")]
3030
public string SomeStringProperty { get; set; }
3131
```
3232

3333
## [Fluent API](#tab/fluent-api)
3434

35-
```c#
35+
```csharp
3636
builder.Entity<Blog>()
3737
.Property(b => b.SomeStringProperty)
3838
.HasColumnType("jsonb");

conceptual/EFCore.PG/mapping/json.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The simplest form of mapping to JSON is via a regular string property, just like
1818

1919
### [Data Annotations](#tab/data-annotations)
2020

21-
```c#
21+
```csharp
2222
public class SomeEntity
2323
{
2424
public int Id { get; set; }
@@ -29,7 +29,7 @@ public class SomeEntity
2929

3030
### [Fluent API](#tab/fluent-api)
3131

32-
```c#
32+
```csharp
3333
class MyContext : DbContext
3434
{
3535
public DbSet<SomeEntity> SomeEntities { get; set; }
@@ -67,7 +67,7 @@ Npgsql's support for `ToJson()` is fully aligned with the general EF support; se
6767

6868
To get you started quickly, assume that we have the following Customer type, with a Details property that we want to map to a single JSON column in the database:
6969

70-
```c#
70+
```csharp
7171
public class Customer
7272
{
7373
public int Id { get; set; }
@@ -90,7 +90,7 @@ public class Order // Part of the JSON column
9090

9191
To instruct EF to map CustomerDetails - and within it, Order - to a JSON column, configure it as follows:
9292

93-
```c#
93+
```csharp
9494
protected override void OnModelCreating(ModelBuilder modelBuilder)
9595
{
9696
modelBuilder.Entity<Customer>()
@@ -112,7 +112,7 @@ To use traditional POCO mapping, configure a property a mapping to map to a `jso
112112

113113
### [Data Annotations](#tab/data-annotations)
114114

115-
```c#
115+
```csharp
116116
public class Customer
117117
{
118118
public int Id { get; set; }
@@ -136,7 +136,7 @@ public class Order // Part of the JSON column
136136

137137
### [Fluent API](#tab/fluent-api)
138138

139-
```c#
139+
```csharp
140140
class MyContext : DbContext
141141
{
142142
public DbSet<SomeEntity> SomeEntities { get; set; }
@@ -178,7 +178,7 @@ Note that when using this mapping, only limited forms of LINQ querying is suppor
178178

179179
If your column JSON schema isn't stable, a strongly-typed POCO mapping may not be appropriate. The Npgsql provider also allows you to map the DOM document type provided by [System.Text.Json APIs](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/).
180180

181-
```c#
181+
```csharp
182182
public class SomeEntity : IDisposable
183183
{
184184
public int Id { get; set; }
@@ -192,7 +192,7 @@ Note that neither a data annotation nor the fluent API are required, as [JsonDoc
192192

193193
Once a document is loaded from the database, you can traverse it:
194194

195-
```c#
195+
```csharp
196196
var someEntity = context.Entities.First();
197197
Console.WriteLine(someEntity.Customer.RootElement.GetProperty("Orders")[0].GetProperty("Price").GetInt32());
198198
```
@@ -208,15 +208,15 @@ Saving and loading documents these documents wouldn't be much use without the ab
208208

209209
### [Classic POCO Mapping](#tab/poco)
210210

211-
```c#
211+
```csharp
212212
var joes = context.CustomerEntries
213213
.Where(e => e.Customer.Name == "Joe")
214214
.ToList();
215215
```
216216

217217
### [JsonDocument Mapping](#tab/jsondocument)
218218

219-
```c#
219+
```csharp
220220
var joes = context.CustomerEntries
221221
.Where(e => e.Customer.RootElement.GetProperty("Name").GetString() == "Joe")
222222
.ToList();

conceptual/EFCore.PG/mapping/nodatime.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To set up the NodaTime plugin, add the [Npgsql.EntityFrameworkCore.PostgreSQL.No
1818

1919
If you're passing a connection string to `UseNpgsql`, simply add the `UseNodaTime` call as follows:
2020

21-
```c#
21+
```csharp
2222
builder.Services.AddDbContext<MyContext>(options => options.UseNpgsql(
2323
"<connection string>",
2424
o => o.UseNodaTime()));
@@ -30,7 +30,7 @@ This configures all aspects of Npgsql to use the NodaTime plugin - both at the E
3030

3131
If you're creating an external NpgsqlDataSource and passing it to `UseNpgsql`, you must call `UseNodaTime` on your NpgsqlDataSourceBuilder independently of the EF-level setup:
3232

33-
```c#
33+
```csharp
3434
var dataSourceBuilder = new NpgsqlDataSourceBuilder("<connection string>");
3535
dataSourceBuilder.UseNodaTime();
3636
var dataSource = dataSourceBuilder.Build();
@@ -42,7 +42,7 @@ builder.Services.AddDbContext<MyContext>(options => options.UseNpgsql(
4242

4343
### [Older EF versions, with a connection string](#tab/legacy-with-connection-string)
4444

45-
```c#
45+
```csharp
4646
// Configure UseNodaTime at the ADO.NET level.
4747
// This code must be placed at the beginning of your application, before any other Npgsql API is called; an appropriate place for this is in the static constructor on your DbContext class:
4848
static MyDbContext()
@@ -57,7 +57,7 @@ builder.Services.AddDbContext<MyContext>(options =>
5757

5858
The above sets up all the necessary mappings and operation translators. You can now use NodaTime types as regular properties in your entities, and even perform some operations:
5959

60-
```c#
60+
```csharp
6161
public class Post
6262
{
6363
public int Id { get; set; }
@@ -72,7 +72,7 @@ var recentPosts = context.Posts.Where(p => p.CreationTime > someInstant);
7272

7373
The provider knows how to translate many members and methods on mapped NodaTime types. For example, the following query will be translated to SQL and evaluated server-side:
7474

75-
```c#
75+
```csharp
7676
// Get all events which occurred on a Monday
7777
var mondayEvents = context.Events.Where(p => p.SomeDate.DayOfWeek == DayOfWeek.Monday);
7878

0 commit comments

Comments
 (0)