Skip to content

Commit

Permalink
Remove relational modeling, clean up concurrency page
Browse files Browse the repository at this point in the history
Closes #1669
  • Loading branch information
roji committed Dec 21, 2019
1 parent e63c8e4 commit 4bfffd6
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 43 deletions.
10 changes: 10 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@
"source_path": "entity-framework/core/modeling/relational/inheritance.md",
"redirect_url": "/ef/core/modeling/inheritance",
"redirect_document_id": false
},
{
"source_path": "entity-framework/core/modeling/relational/",
"redirect_url": "/ef/core/modeling/",
"redirect_document_id": false
},
{
"source_path": "entity-framework/core/modeling/relational/index",
"redirect_url": "/ef/core/modeling/",
"redirect_document_id": false
}
]
}
38 changes: 14 additions & 24 deletions entity-framework/core/modeling/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,30 @@ uid: core/modeling/concurrency
Properties configured as concurrency tokens are used to implement optimistic concurrency control.

## Conventions
## Configuration

By convention, properties are never configured as concurrency tokens.
### [Data Annotations](#tab/data-annotations)

## Data Annotations
[!code-csharp[Main](../../../samples/core/Modeling/DataAnnotations/Concurrency.cs?name=Concurrency&highlight=5)]

You can use the Data Annotations to configure a property as a concurrency token.
### [Fluent API](#tab/fluent-api)

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

## Fluent API
***

You can use the Fluent API to configure a property as a concurrency token.
## Timestamp/rowversion

[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/Concurrency.cs#ConfigureConcurrencyFluent)]
A timestamp/rowversion is a property for which a new value is automatically generated by the database every time a row is inserted or updated. The property is also treated as a concurrency token, ensuring that you get an exception if a row you are updating has changed since you queried it. The precise details depend on the database provider being used; for SQL Server, a *byte[]* property is usually used, which will be set up as a *ROWVERSION* column in the database.

## Timestamp/row version
You can configure a property to be a timestamp/rowversion as follows:

A timestamp is a property where a new value is generated by the database every time a row is inserted or updated. The property is also treated as a concurrency token. This ensures you will get an exception if anyone else has modified a row that you are trying to update since you queried for the data.
### [Data Annotations](#tab/data-annotations)

How this is achieved is up to the database provider being used. For SQL Server, timestamp is usually used on a *byte[]* property, which will be setup as a *ROWVERSION* column in the database.
[!code-csharp[Main](../../../samples/core/Modeling/DataAnnotations/Timestamp.cs?name=Timestamp&highlight=9,17)]

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

By convention, properties are never configured as timestamps.
[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/Timestamp.cs?name=Timestamp&highlight=7)]

### Data Annotations

You can use Data Annotations to configure a property as a timestamp.

[!code-csharp[Main](../../../samples/core/Modeling/DataAnnotations/Timestamp.cs#ConfigureTimestampAnnotations)]

### Fluent API

You can use the Fluent API to configure a property as a timestamp.

[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/Timestamp.cs#ConfigureTimestampFluent)]
***
10 changes: 0 additions & 10 deletions entity-framework/core/modeling/relational/index.md

This file was deleted.

4 changes: 0 additions & 4 deletions entity-framework/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@
- name: Spatial Data
displayName: GIS
href: core/modeling/spatial.md
- name: Relational database modeling
items:
- name: Overview
href: core/modeling/relational/index.md
- name: Managing Database Schemas
items:
- name: Overview
Expand Down
2 changes: 1 addition & 1 deletion samples/core/Modeling/DataAnnotations/Concurrency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MyContext : DbContext
public DbSet<Person> People { get; set; }
}

#region ConfigureConcurrencyAnnotations
#region Concurrencty
public class Person
{
public int PersonId { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion samples/core/Modeling/DataAnnotations/Timestamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MyContext : DbContext
public DbSet<Blog> Blogs { get; set; }
}

#region ConfigureTimestampAnnotations
#region Timestamp
public class Blog
{
public int BlogId { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions samples/core/Modeling/FluentAPI/Concurrency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace EFModeling.FluentAPI.Concurrency
{
#region ConfigureConcurrencyFluent
class MyContext : DbContext
{
public DbSet<Person> People { get; set; }

#region Concurrency
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Person>()
.Property(p => p.LastName)
.IsConcurrencyToken();
}
#endregion
}

public class Person
Expand All @@ -21,5 +22,4 @@ public class Person
public string LastName { get; set; }
public string FirstName { get; set; }
}
#endregion
}
2 changes: 1 addition & 1 deletion samples/core/Modeling/FluentAPI/Timestamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EFModeling.FluentAPI.Timestamp
{
#region ConfigureTimestampFluent
#region Timestamp
class MyContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
Expand Down

0 comments on commit 4bfffd6

Please sign in to comment.