60 lines
2.5 KiB
C#
60 lines
2.5 KiB
C#
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace RobotNet10.FleetManager.Data
|
|
{
|
|
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : IdentityDbContext<ApplicationUser>(options)
|
|
{
|
|
/// <summary>
|
|
/// Robot models
|
|
/// </summary>
|
|
public DbSet<RobotModel> RobotModels { get; set; }
|
|
|
|
/// <summary>
|
|
/// Robots
|
|
/// </summary>
|
|
public DbSet<Robot> Robots { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
// Configure RobotModel
|
|
modelBuilder.Entity<RobotModel>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.ModelName).HasDatabaseName("IX_RobotModels_ModelName");
|
|
entity.HasIndex(e => e.NavigationType).HasDatabaseName("IX_RobotModels_NavigationType");
|
|
entity.HasIndex(e => e.VehicleTypeId).HasDatabaseName("IX_RobotModels_VehicleTypeId");
|
|
|
|
entity.Property(e => e.ModelName).IsRequired().HasMaxLength(256);
|
|
entity.Property(e => e.Length).HasPrecision(18, 2);
|
|
entity.Property(e => e.Width).HasPrecision(18, 2);
|
|
entity.Property(e => e.NavigationPointX).HasPrecision(18, 2);
|
|
entity.Property(e => e.NavigationPointY).HasPrecision(18, 2);
|
|
entity.Property(e => e.CreatedDate).IsRequired();
|
|
});
|
|
|
|
// Configure Robot
|
|
modelBuilder.Entity<Robot>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.RobotId).IsUnique().HasDatabaseName("UX_Robots_RobotId");
|
|
entity.HasIndex(e => e.ModelId).HasDatabaseName("IX_Robots_ModelId");
|
|
entity.HasIndex(e => e.MapId).HasDatabaseName("IX_Robots_MapId");
|
|
|
|
entity.Property(e => e.RobotId).IsRequired().HasMaxLength(64);
|
|
entity.Property(e => e.Name).IsRequired().HasMaxLength(256);
|
|
entity.Property(e => e.ModelId).IsRequired();
|
|
entity.Property(e => e.CreatedDate).IsRequired();
|
|
|
|
// Foreign key relationship
|
|
entity.HasOne(e => e.Model)
|
|
.WithMany(m => m.Robots)
|
|
.HasForeignKey(e => e.ModelId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
});
|
|
}
|
|
}
|
|
}
|