Skip to content

Commit 1a68d1a

Browse files
committed
Move sequences modeling page out of relational and clean up
Part of #1669
1 parent 6772785 commit 1a68d1a

File tree

7 files changed

+43
-71
lines changed

7 files changed

+43
-71
lines changed

.openpublishing.redirection.json

+5
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@
289289
"source_path": "entity-framework/core/modeling/relational/unique-constraints.md",
290290
"redirect_url": "/ef/core/modeling/keys",
291291
"redirect_document_id": false
292+
},
293+
{
294+
"source_path": "entity-framework/core/modeling/relational/sequences.md",
295+
"redirect_url": "/ef/core/modeling/sequences",
296+
"redirect_document_id": false
292297
}
293298
]
294299
}

entity-framework/core/modeling/relational/sequences.md

-35
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Sequences - EF Core
3+
author: roji
4+
ms.date: 12/18/2019
5+
ms.assetid: 94f81a92-3c72-4e14-912a-f99310374e42
6+
uid: core/modeling/sequences
7+
---
8+
# Sequences
9+
10+
> [!NOTE]
11+
> Sequences are a feature typically supported only by relational databases. If you're using a non-relational database such as Cosmos, check your database documentation on generating unique values.
12+
13+
A sequence generates unique, sequential numeric values in the database. Sequences are not associated with a specific table, and multiple tables can be set up to draw values from the same sequence.
14+
15+
## Basic usage
16+
17+
You can set up a sequence in the model, and then use it to generate values for properties:
18+
19+
[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/Sequence.cs?name=Sequence&highlight=3,7)]
20+
21+
Note that the specific SQL used to generate a value from a sequence is database-specific; the above example works on SQL Server but will fail on other databases. Consult your specific database's documentation for more information.
22+
23+
## Configuring sequence settings
24+
25+
You can also configure additional aspects of the sequence, such as its schema, start value, increment, etc.:
26+
27+
[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/SequenceConfiguration.cs?name=SequenceConfiguration&highlight=3-5)]

entity-framework/toc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
href: core/modeling/indexes.md
9898
- name: Inheritance
9999
href: core/modeling/inheritance.md
100+
- name: Sequences
101+
href: core/modeling/sequences.md
100102
- name: Backing Fields
101103
href: core/modeling/backing-field.md
102104
- name: Value Conversions
@@ -122,8 +124,6 @@
122124
href: core/modeling/relational/index.md
123125
- name: Computed Columns
124126
href: core/modeling/relational/computed-columns.md
125-
- name: Sequences
126-
href: core/modeling/relational/sequences.md
127127
- name: Default Values
128128
href: core/modeling/relational/default-values.md
129129
- name: Inheritance (Relational Database)

samples/core/Modeling/FluentAPI/Relational/SequenceUsed.cs

-29
This file was deleted.

samples/core/Modeling/FluentAPI/Relational/Sequence.cs renamed to samples/core/Modeling/FluentAPI/Sequence.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
namespace EFModeling.FluentAPI.Relational.Sequence
44
{
5-
#region Model
65
class MyContext : DbContext
76
{
87
public DbSet<Order> Orders { get; set; }
98

9+
#region Sequence
1010
protected override void OnModelCreating(ModelBuilder modelBuilder)
1111
{
1212
modelBuilder.HasSequence<int>("OrderNumbers");
13+
14+
modelBuilder.Entity<Order>()
15+
.Property(o => o.OrderNo)
16+
.HasDefaultValueSql("NEXT VALUE FOR shared.OrderNumbers");
1317
}
18+
#endregion
1419
}
1520

1621
public class Order
@@ -19,5 +24,4 @@ public class Order
1924
public int OrderNo { get; set; }
2025
public string Url { get; set; }
2126
}
22-
#endregion
2327
}

samples/core/Modeling/FluentAPI/Relational/SequenceConfigured.cs renamed to samples/core/Modeling/FluentAPI/SequenceConfiguration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
using Microsoft.EntityFrameworkCore;
22

3-
namespace EFModeling.FluentAPI.Relational.SequenceConfigured
3+
namespace EFModeling.FluentAPI.Relational.SequenceConfiguration
44
{
5-
#region Sequence
65
class MyContext : DbContext
76
{
87
public DbSet<Order> Orders { get; set; }
98

9+
#region SequenceConfiguration
1010
protected override void OnModelCreating(ModelBuilder modelBuilder)
1111
{
1212
modelBuilder.HasSequence<int>("OrderNumbers", schema: "shared")
1313
.StartsAt(1000)
1414
.IncrementsBy(5);
1515
}
16+
#endregion
1617
}
17-
#endregion
1818

1919
public class Order
2020
{

0 commit comments

Comments
 (0)