mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
added Data, Models, EntityFramework
This commit is contained in:
36
Data/LiveGameContext.cs
Normal file
36
Data/LiveGameContext.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LiveGameFeed.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
|
||||
namespace LiveGameFeed.Data
|
||||
{
|
||||
public class LiveGameContext : DbContext
|
||||
{
|
||||
public DbSet<Match> Matches { get; set; }
|
||||
public DbSet<Feed> Feeds { get; set; }
|
||||
|
||||
public LiveGameContext(DbContextOptions options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
|
||||
{
|
||||
relationship.DeleteBehavior = DeleteBehavior.Restrict;
|
||||
}
|
||||
|
||||
modelBuilder.Entity<Match>()
|
||||
.ToTable("Match");
|
||||
|
||||
modelBuilder.Entity<Feed>()
|
||||
.ToTable("Feed");
|
||||
|
||||
modelBuilder.Entity<Feed>()
|
||||
.Property(f => f.MatchId)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user