Skip to content

Commit e0b208d

Browse files
🔨 Implement Sample Db Context
1 parent 2fc4c2f commit e0b208d

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using EntityFrameworkCore.DataEncryption.Conversions;
2+
using EntityFrameworkCore.DataEncryption.Sample.Entities;
3+
using Microsoft.EntityFrameworkCore;
4+
5+
namespace EntityFrameworkCore.DataEncryption.Sample.Context;
6+
7+
/// <summary>
8+
/// Sample Db Context
9+
/// </summary>
10+
public class SampleDbContext : DbContext
11+
{
12+
/// <summary>
13+
/// protected ctor
14+
/// </summary>
15+
protected SampleDbContext()
16+
{
17+
}
18+
19+
/// <summary>
20+
/// public ctor
21+
/// </summary>
22+
/// <param name="options">
23+
/// DbContext Options object. <see cref="DbContextOptions{TContext}"/>
24+
/// </param>
25+
public SampleDbContext(DbContextOptions options) : base(options)
26+
{
27+
}
28+
29+
public virtual DbSet<Author> Authors { get; set; }
30+
31+
protected override void OnModelCreating(ModelBuilder modelBuilder)
32+
{
33+
modelBuilder.Entity<Author>(entity =>
34+
{
35+
entity
36+
.Property(p => p.Id)
37+
.UseIdentityColumn();
38+
39+
entity
40+
.Property(p => p.Name)
41+
.IsRequired()
42+
.HasMaxLength(2048);
43+
44+
entity
45+
.Property(p => p.Surname)
46+
.IsRequired()
47+
.HasMaxLength(2048);
48+
49+
entity
50+
.Property(p => p.Phone)
51+
.IsRequired()
52+
.HasConversion(new EncryptValueConverter("89acMXSBpuEBDWHZ"));
53+
});
54+
base.OnModelCreating(modelBuilder);
55+
}
56+
}

0 commit comments

Comments
 (0)