You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.4 KiB
27 lines
1.4 KiB
using Infrastructure.Application.Entites.Settings;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace IoT.Shared
|
|
{
|
|
public class IoTSharedDbConfig
|
|
{
|
|
public static void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<Setting>().Property(o=>o.Name).IsRequired();
|
|
modelBuilder.Entity<Setting>().HasIndex(o => o.Name).IsUnique();
|
|
//
|
|
modelBuilder.Entity<IoTGateway>().HasIndex(o => o.Number).IsUnique();
|
|
//
|
|
modelBuilder.Entity<IoTProduct>().HasIndex(o => o.Number).IsUnique();
|
|
modelBuilder.Entity<IoTApi>().HasOne(o => o.Product).WithMany(o => o.Apis).HasForeignKey(o => o.ProductId);
|
|
modelBuilder.Entity<IoTApi>().HasIndex(o => new { o.ProductId, o.Name }).IsUnique();
|
|
modelBuilder.Entity<IoTParameter>().HasOne(o => o.Api).WithMany(o => o.Parameters).HasForeignKey(o => o.ApiId);
|
|
//
|
|
modelBuilder.Entity<IoTDevice>().HasOne(o => o.Product).WithMany(o => o.Devices).HasForeignKey(o => o.ProductId);
|
|
modelBuilder.Entity<IoTDevice>().HasOne(o => o.Node).WithMany(o => o.Devices).HasForeignKey(o => o.NodeId);
|
|
modelBuilder.Entity<IoTDevice>().HasIndex(o => o.Number).IsUnique();
|
|
modelBuilder.Entity<IoTData>().HasOne(o => o.Device).WithMany(o => o.Data).HasForeignKey(o => o.DeviceId);
|
|
}
|
|
}
|
|
} |