genre added
This commit is contained in:
@@ -13,7 +13,11 @@ namespace WatchIt.Database.Model
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public static void Build<T>(ModelBuilder builder) where T : class, IEntity<T> => Build<T>(builder.Entity<T>());
|
||||
public static void Build<T>(EntityTypeBuilder<T> builder) where T : class, IEntity<T> => T.Build(builder);
|
||||
public static void Build<T>(EntityTypeBuilder<T> builder) where T : class, IEntity<T>
|
||||
{
|
||||
T.Build(builder);
|
||||
builder.HasData(T.InsertData());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
49
WatchIt.Database/WatchIt.Database.Model/Genre/Genre.cs
Normal file
49
WatchIt.Database/WatchIt.Database.Model/Genre/Genre.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WatchIt.Database.Model.Genre
|
||||
{
|
||||
public class Genre : IEntity<Genre>
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public short Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
static void IEntity<Genre>.Build(EntityTypeBuilder<Genre> builder)
|
||||
{
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.HasIndex(x => x.Id)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.Id)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.Name)
|
||||
.HasMaxLength(100)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.Description)
|
||||
.HasMaxLength(1000);
|
||||
}
|
||||
|
||||
static IEnumerable<Genre> IEntity<Genre>.InsertData() => new List<Genre>
|
||||
{
|
||||
new Genre { Id = 1, Name = "Comedy" },
|
||||
new Genre { Id = 2, Name = "Thriller" },
|
||||
new Genre { Id = 3, Name = "Horror" },
|
||||
};
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ namespace WatchIt.Database.Model
|
||||
#region METHODS
|
||||
|
||||
static abstract void Build(EntityTypeBuilder<T> builder);
|
||||
static virtual IEnumerable<T> InsertData() => Array.Empty<T>();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user