~ruther/NosSmooth

ref: fcd0751c2f76ffee45134260ce9d7c0bddf837d2 NosSmooth/Data/NosSmooth.Data.Database/NostaleDataContext.cs -rw-r--r-- 2.0 KiB
fcd0751c — František Boháček Merge pull request #22 from Rutherther/data 3 years ago
                                                                                
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
//  NostaleDataContext.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.EntityFrameworkCore;
using NosSmooth.Data.Database.Data;

namespace NosSmooth.Data.Database;

/// <summary>
/// Database context with NosTale data.
/// </summary>
public class NostaleDataContext : DbContext
{
    /// <summary>
    /// Initializes a new instance of the <see cref="NostaleDataContext"/> class.
    /// </summary>
    /// <param name="options">The options.</param>
    public NostaleDataContext(DbContextOptions<NostaleDataContext> options)
        : base(options)
    {
    }

    /// <summary>
    /// Gets the translations set.
    /// </summary>
    public DbSet<Translation> Translations => Set<Translation>();

    /// <summary>
    /// Gets the items set.
    /// </summary>
    public DbSet<ItemInfo> Items => Set<ItemInfo>();

    /// <summary>
    /// Gets the maps set.
    /// </summary>
    public DbSet<MapInfo> Maps => Set<MapInfo>();

    /// <summary>
    /// Gets the monsters set.
    /// </summary>
    public DbSet<MonsterInfo> Monsters => Set<MonsterInfo>();

    /// <summary>
    /// Gets the skills set.
    /// </summary>
    public DbSet<SkillInfo> Skills => Set<SkillInfo>();

    /// <inheritdoc />
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ItemInfo>()
            .Property(x => x.Data)
            .HasConversion
            (
                x => string.Join("|", x),
                x => x.Split(',', StringSplitOptions.RemoveEmptyEntries)
            );

        modelBuilder.Entity<Translation>().HasKey("Language", "Root", "Key");

        modelBuilder.Entity<ItemInfo>().Ignore(x => x.Name);
        modelBuilder.Entity<SkillInfo>().Ignore(x => x.Name);
        modelBuilder.Entity<MonsterInfo>().Ignore(x => x.Name);
        modelBuilder.Entity<MapInfo>().Ignore(x => x.Name);
        base.OnModelCreating(modelBuilder);
    }
}
Do not follow this link