Get items stored and retrieved from the db

This commit is contained in:
TheXamlGuy
2024-05-12 14:50:10 +01:00
parent fd1c7e01be
commit c5c2756c5b
15 changed files with 84 additions and 90 deletions
-11
View File
@@ -1,11 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Bitvault.Data;
public record Category
{
[Key]
public int Id { get; set; }
public string? Name { get; set; }
}
@@ -1,26 +1,23 @@
using Bitvault.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Bitvault.Data;
public class VaultDbContext(DbContextOptions<VaultDbContext> options) :
public class ContainerDbContext(DbContextOptions<ContainerDbContext> options) :
DbContext(options)
{
public DbSet<Category> Categories { get; set; }
public DbSet<Document> Documents { get; set; }
public DbSet<Content> Items { get; set; }
public DbSet<Item> Items { get; set; }
public DbSet<Tag> Tags { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Content>()
modelBuilder.Entity<Item>()
.HasMany(x => x.Tags)
.WithOne();
modelBuilder.Entity<Content>()
modelBuilder.Entity<Item>()
.HasMany(x => x.Documents)
.WithOne();
}
@@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
namespace Bitvault.Data;
public record Content
public record Item
{
[Key]
public int Id { get; set; }
@@ -12,11 +12,9 @@ public record Content
public string? Description { get; set; }
public int State { get; set; }
public int State { get; set; } = 0;
public ICollection<Tag>? Tags { get; }
public Category? Category { get; }
public ICollection<Document>? Documents { get; }
}