Программа просмотра базы данных

This commit is contained in:
2025-04-18 17:26:52 +04:00
parent 372e41e51a
commit 9a711c5a9d
27 changed files with 701 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
using Pf2eModel.Model.Base;
using Pf2eModel.Model;
using Pf2eModel.Model.Enum;
using System.Reflection;
namespace Pf2eModel;
[AttributeUsage(AttributeTargets.Class)]
public class EntityOfTypeAttribute(EntityType type) : Attribute
{
public EntityType Type { get; } = type;
public static Type Resolve(Entity entity)
{
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
{
if (type.GetCustomAttributes(typeof(EntityOfTypeAttribute), true).Length <= 0)
{
continue;
}
if (!type.IsAssignableTo(typeof(IEntity)))
{
throw new Exception($"'EntityOfTypeAttribute' attribute should only be applied to children of 'IEntity' class. '{type.FullName}' is not.");
}
EntityOfTypeAttribute attribute = type.GetCustomAttribute<EntityOfTypeAttribute>()!;
if (attribute.Type == entity.Type)
{
return type;
}
}
throw new Exception($"Can't resolve class associated with '{entity.Type}' EntityType.");
}
}
+2
View File
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@@ -18,5 +19,6 @@ public partial class EntityAlias
[MaxLength(Pf2eDbContext.NameLength)]
public string Alias { get; set; } = null!;
[JsonIgnore]
public virtual Entity Entity { get; set; } = null!;
}
+1
View File
@@ -13,6 +13,7 @@ public partial class Keyword
[Column(Order = 2)]
public string Slug { get; set; } = null!;
[Newtonsoft.Json.JsonIgnore]
public virtual ICollection<Entity> Entities { get; set; } = [];
public virtual ICollection<KeywordAlias> Aliases { get; set; } = [];
@@ -17,5 +17,6 @@ public partial class KeywordAlias
[MaxLength(Pf2eDbContext.NameLength)]
public string Value { get; set; } = null!;
[Newtonsoft.Json.JsonIgnore]
public virtual Keyword Keyword { get; set; } = null!;
}
@@ -22,6 +22,7 @@ public partial class EntitySource
[Comment("Флаг, указывающий, что объект является частью ремастера")]
public bool IsRemaster { get; set; }
[Newtonsoft.Json.JsonIgnore]
public virtual Entity Entity { get; set; } = null!;
public virtual Source Source { get; set; } = null!;
+1
View File
@@ -22,5 +22,6 @@ public partial class Source
public DateOnly? ReleaseDate { get; set; }
[Newtonsoft.Json.JsonIgnore]
public ICollection<EntitySource> EntitySources { get; set; } = [];
}
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@@ -23,6 +24,7 @@ public partial class EntityExternal
[Comment("Контроль версии объекта")]
public string Md5 { get; set; } = null!;
[Newtonsoft.Json.JsonIgnore]
public virtual Entity Entity { get; set; } = null!;
public virtual ExternalTarget Target { get; set; } = null!;
@@ -23,5 +23,6 @@ public partial class ExternalTarget
public string Prefix { get; set; } = null!;
[Column(Order = 4)]
[Newtonsoft.Json.JsonIgnore]
public virtual ICollection<EntityExternal> EntityExternals { get; set; } = [];
}
+3 -1
View File
@@ -1,4 +1,5 @@
using Pf2eModel.Model.Base;
using Newtonsoft.Json;
using Pf2eModel.Model.Base;
namespace Pf2eModel.Model;
@@ -6,6 +7,7 @@ public interface IEntity
{
public int Id { get; set; }
[JsonIgnore]
public Entity Entity { get; set; }
}
+1
View File
@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Action)]
public partial class Action : IEntity
{
[System.ComponentModel.DataAnnotations.Key]
+1
View File
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Ancestry)]
public partial class Ancestry : IEntity
{
[System.ComponentModel.DataAnnotations.Key]
+2
View File
@@ -1,10 +1,12 @@
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.BackgroundRelation;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Background)]
public partial class Background : IEntity
{
[Key]
+2
View File
@@ -1,10 +1,12 @@
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.ClassRelation;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Class)]
public partial class Class : IEntity
{
[Key]
+1
View File
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Condition)]
public partial class Condition : IEntity
{
[Key]
+1
View File
@@ -7,6 +7,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Deity)]
public partial class Deity : IEntity
{
[Key]
+1
View File
@@ -6,6 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Feat)]
public partial class Feat : IEntity
{
[Key]
+2
View File
@@ -1,9 +1,11 @@
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Heritage)]
public partial class Heritage : IEntity
{
[Key]
+2
View File
@@ -1,10 +1,12 @@
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.SpellRelation;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Spell)]
public partial class Spell : IEntity
{
[Key]
+2
View File
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Trait)]
public partial class Trait : IEntity
{
[Key]
@@ -17,5 +18,6 @@ public partial class Trait : IEntity
[Column(Order = 2)]
public TraitType Type { get; set; }
[Newtonsoft.Json.JsonIgnore]
public virtual ICollection<Entity> Entities { get; set; } = [];
}
+1
View File
@@ -22,6 +22,7 @@
<!--<PrivateAssets>all</PrivateAssets>-->
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="9.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup>