/* * OCPP.Core - https://github.com/dallmann-consulting/OCPP.Core * Copyright (C) 2020-2021 dallmann consulting GmbH. * All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ using System; using System.IO; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.Extensions.Configuration; #nullable disable namespace OCPP.Core.Database { public partial class OCPPCoreContext : DbContext { public OCPPCoreContext(DbContextOptions options) : base(options) { } public virtual DbSet ChargePoints { get; set; } public virtual DbSet ChargeTags { get; set; } public virtual DbSet ConnectorStatuses { get; set; } public virtual DbSet MessageLogs { get; set; } public virtual DbSet Transactions { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { entity.ToTable("ChargePoint"); entity.HasIndex(e => e.ChargePointId, "ChargePoint_Identifier") .IsUnique(); entity.Property(e => e.ChargePointId).HasMaxLength(100); entity.Property(e => e.Comment).HasMaxLength(200); entity.Property(e => e.Name).HasMaxLength(100); entity.Property(e => e.Username).HasMaxLength(50); entity.Property(e => e.Password).HasMaxLength(50); entity.Property(e => e.ClientCertThumb).HasMaxLength(100); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.TagId) .HasName("PK_ChargeKeys"); entity.Property(e => e.TagId).HasMaxLength(50); entity.Property(e => e.ParentTagId).HasMaxLength(50); entity.Property(e => e.TagName).HasMaxLength(200); }); modelBuilder.Entity(entity => { entity.HasKey(e => new { e.ChargePointId, e.ConnectorId }); entity.ToTable("ConnectorStatus"); entity.Property(e => e.ChargePointId).HasMaxLength(100); entity.Property(e => e.ConnectorName).HasMaxLength(100); entity.Property(e => e.LastStatus).HasMaxLength(100); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.LogId); entity.ToTable("MessageLog"); entity.HasIndex(e => e.LogTime, "IX_MessageLog_ChargePointId"); entity.Property(e => e.ChargePointId) .IsRequired() .HasMaxLength(100); entity.Property(e => e.ErrorCode).HasMaxLength(100); entity.Property(e => e.Message) .IsRequired() .HasMaxLength(100); }); modelBuilder.Entity(entity => { entity.Property(e => e.Uid).HasMaxLength(50); entity.Property(e => e.ChargePointId) .IsRequired() .HasMaxLength(100); entity.Property(e => e.StartResult).HasMaxLength(100); entity.Property(e => e.StartTagId).HasMaxLength(50); entity.Property(e => e.StopReason).HasMaxLength(100); entity.Property(e => e.StopTagId).HasMaxLength(50); entity.HasOne(d => d.ChargePoint) .WithMany(p => p.Transactions) .HasForeignKey(d => d.ChargePointId) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_Transactions_ChargePoint"); entity.HasIndex(e => new { e.ChargePointId, e.ConnectorId }); }); OnModelCreatingPartial(modelBuilder); } partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } }