first commit -push
This commit is contained in:
21
RobotNet.RobotManager/Data/RobotEditorDbContext.cs
Normal file
21
RobotNet.RobotManager/Data/RobotEditorDbContext.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace RobotNet.RobotManager.Data;
|
||||
|
||||
public class RobotEditorDbContext(DbContextOptions<RobotEditorDbContext> options) : DbContext(options)
|
||||
{
|
||||
public DbSet<Robot> Robots { get; private set; }
|
||||
public DbSet<RobotModel> RobotModels { get; private set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<RobotModel>()
|
||||
.HasMany(e => e.Robots)
|
||||
.WithOne(e => e.Model)
|
||||
.HasForeignKey(e => e.ModelId)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user