-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPageContext.cs
36 lines (33 loc) · 1.65 KB
/
PageContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Cloudy.NET.EntitySupport.Serialization;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
namespace TestWebsite.Models
{
public class PageContext : DbContext
{
public PageContext(DbContextOptions<PageContext> options) : base(options) { }
public DbSet<Page> Pages { get; set; }
public DbSet<PageTree> PageTree { get; set; }
public DbSet<StartPage> StartPages { get; set; }
public DbSet<CompositeKeyTest> CompositeKeyTests { get; set; }
public DbSet<SimpleKeyTest> SimpleKeyTests { get; set; }
public DbSet<PropertyTestBed> PropertyTestBeds { get; set; }
public DbSet<SiteSettings> SiteSettings { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<SimpleKeyTest>().Property(p => p.RelatedPage).SerializeIntoJson();
modelBuilder.Entity<CompositeKeyTest>().HasKey(p => new { p.FirstPrimaryKey, p.SecondPrimaryKey });
modelBuilder.Entity<CompositeKeyTest>().Property(p => p.RelatedObject).SerializeIntoJson();
modelBuilder.Entity<Page>().Property(p => p.Blocks).JsonBlockConversion();
modelBuilder.Entity<PropertyTestBed>().Property(p => p.Colors).SerializeIntoJson();
modelBuilder.Entity<PageTree>().Property(p => p.Ancestors).SerializeIntoJson();
modelBuilder.Entity<PageTree>().Property(p => p.Children).SerializeIntoJson();
}
}
}