Skip to content
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

Document comments #2893

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions entity-framework/core/modeling/entity-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,20 @@ A collation can be defined on text columns, determining how they are compared an
If all columns in a database need to use a certain collation, define the collation at the database level instead.

General information about EF Core support for collations can be found in the [collation documentation page](xref:core/miscellaneous/collations-and-case-sensitivity).

## Column comments

You can set an arbitrary text comment that gets set on the database column, allowing you to document your schema in the database:

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

> [!NOTE]
> Setting comments via data annotations was introduced in EF Core 5.0.

[!code-csharp[Main](../../../samples/core/Modeling/DataAnnotations/ColumnComment.cs?name=ColumnComment&highlight=4)]

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

[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/ColumnComment.cs?name=ColumnComment&highlight=5)]

***
17 changes: 17 additions & 0 deletions entity-framework/core/modeling/entity-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ Entity types can be mapped to database views using the Fluent API.

> [!TIP]
> To test entity types mapped to views using the in-memory provider map them to a query via `ToInMemoryQuery`. See a [runnable sample](https://github.com/dotnet/EntityFramework.Docs/tree/master/samples/core/Miscellaneous/Testing/ItemsWebApi/) using this technique for more details.

## Table comments

You can set an arbitrary text comment that gets set on the database table, allowing you to document your schema in the database:

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

> [!NOTE]
> Setting comments via data annotations was introduced in EF Core 5.0.

[!code-csharp[Main](../../../samples/core/Modeling/DataAnnotations/TableComment.cs?name=TableComment&highlight=1)]

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

[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/TableComment.cs?name=TableComment&highlight=4)]

***
19 changes: 19 additions & 0 deletions samples/core/Modeling/DataAnnotations/ColumnComment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;

namespace EFModeling.DataAnnotations.Relational.ColumnComment
{
class MyContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
}

#region ColumnComment
public class Blog
{
public int BlogId { get; set; }
[Comment("The URL of the blog")]
public string Url { get; set; }
}
#endregion
}
19 changes: 19 additions & 0 deletions samples/core/Modeling/DataAnnotations/TableComment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;

namespace EFModeling.DataAnnotations.Relational.TableComment
{
class MyContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
}

#region TableComment
[Comment("Blogs managed on the website")]
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
}
#endregion
}
25 changes: 25 additions & 0 deletions samples/core/Modeling/FluentAPI/ColumnComment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using System;

namespace EFModeling.FluentAPI.ColumnComment
{
class MyContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }

#region ColumnComment
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.Property(b => b.Url)
.HasComment("The URL of the blog");
}
#endregion
}

public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
}
}
24 changes: 24 additions & 0 deletions samples/core/Modeling/FluentAPI/TableComment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
using System;

namespace EFModeling.FluentAPI.TableComment
{
class MyContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }

#region TableComment
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.HasComment("Blogs managed on the website");
}
#endregion
}

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