Skip to content

Commit

Permalink
Move sequences modeling page out of relational and clean up
Browse files Browse the repository at this point in the history
Part of #1669
  • Loading branch information
roji committed Dec 20, 2019
1 parent 6772785 commit db44ed6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@
"source_path": "entity-framework/core/modeling/relational/unique-constraints.md",
"redirect_url": "/ef/core/modeling/keys",
"redirect_document_id": false
},
{
"source_path": "entity-framework/core/modeling/relational/sequences.md",
"redirect_url": "/ef/core/modeling/sequences",
"redirect_document_id": false
}
]
}
35 changes: 0 additions & 35 deletions entity-framework/core/modeling/relational/sequences.md

This file was deleted.

27 changes: 27 additions & 0 deletions entity-framework/core/modeling/sequences.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Sequences - EF Core
author: roji
ms.date: 12/18/2019
ms.assetid: 94f81a92-3c72-4e14-912a-f99310374e42
uid: core/modeling/sequences
---
# Sequences

> [!NOTE]
> 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.
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.

## Basic usage

You can set up a sequence in the model, and then use it to generate values for properties:

[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/Sequence.cs?name=Sequence&highlight=3,7)]

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.

## Configuring sequence settings

You can also configure additional aspects of the sequence, such as its schema, start value, increment, etc.:

[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/SequenceConfiguration.cs?name=SequenceConfiguration&highlight=3-5)]
4 changes: 2 additions & 2 deletions entity-framework/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
href: core/modeling/indexes.md
- name: Inheritance
href: core/modeling/inheritance.md
- name: Sequences
href: core/modeling/sequences.md
- name: Backing Fields
href: core/modeling/backing-field.md
- name: Value Conversions
Expand All @@ -122,8 +124,6 @@
href: core/modeling/relational/index.md
- name: Computed Columns
href: core/modeling/relational/computed-columns.md
- name: Sequences
href: core/modeling/relational/sequences.md
- name: Default Values
href: core/modeling/relational/default-values.md
- name: Inheritance (Relational Database)
Expand Down
29 changes: 0 additions & 29 deletions samples/core/Modeling/FluentAPI/Relational/SequenceUsed.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

namespace EFModeling.FluentAPI.Relational.Sequence
{
#region Model
class MyContext : DbContext
{
public DbSet<Order> Orders { get; set; }

#region Sequence
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasSequence<int>("OrderNumbers");

modelBuilder.Entity<Order>()
.Property(o => o.OrderNo)
.HasDefaultValueSql("NEXT VALUE FOR shared.OrderNumbers");
}
#endregion
}

public class Order
Expand All @@ -19,5 +24,4 @@ public class Order
public int OrderNo { get; set; }
public string Url { get; set; }
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using Microsoft.EntityFrameworkCore;

namespace EFModeling.FluentAPI.Relational.SequenceConfigured
namespace EFModeling.FluentAPI.Relational.SequenceConfiguration
{
#region Sequence
class MyContext : DbContext
{
public DbSet<Order> Orders { get; set; }

#region SequenceConfiguration
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasSequence<int>("OrderNumbers", schema: "shared")
.StartsAt(1000)
.IncrementsBy(5);
}
#endregion
}
#endregion

public class Order
{
Expand Down

0 comments on commit db44ed6

Please sign in to comment.