using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using FMSAdmin.Entities;
using Microsoft.Extensions.Logging;

namespace FMSAdmin.Data {
    public partial class FMSContext : DbContext {
        private readonly ILogger<FMSContext> _logger;

        public FMSContext(DbContextOptions<FMSContext> options, ILogger<FMSContext> logger = null) : base(options) {
            _logger = logger;
        }

        public virtual DbSet<BemsAlarmGroup> BemsAlarmGroup { get; set; }
        public virtual DbSet<BemsAlarmGroupUser> BemsAlarmGroupUser { get; set; }
        public virtual DbSet<BemsAlarmLog> BemsAlarmLog { get; set; }
        public virtual DbSet<BemsAlarmSetting> BemsAlarmSetting { get; set; }
        public virtual DbSet<BemsAnalysisType> BemsAnalysisType { get; set; }
        public virtual DbSet<BemsChartInfo> BemsChartInfo { get; set; }
        public virtual DbSet<BemsControlAhutempConfig> BemsControlAhutempConfig { get; set; }
        public virtual DbSet<BemsControlGroup> BemsControlGroup { get; set; }
        public virtual DbSet<BemsControlGroupHistory> BemsControlGroupHistory { get; set; }
        public virtual DbSet<BemsControlPointHistory> BemsControlPointHistory { get; set; }
        public virtual DbSet<BemsDevice> BemsDevice { get; set; }
        public virtual DbSet<BemsDeviceRunHistory> BemsDeviceRunHistory { get; set; }
        public virtual DbSet<BemsDeviceRunHourly> BemsDeviceRunHourly { get; set; }
        public virtual DbSet<BemsDeviceRunHourly2> BemsDeviceRunHourly2 { get; set; }
        public virtual DbSet<BemsDeviceRunHourlyCombine> BemsDeviceRunHourlyCombine { get; set; }
        public virtual DbSet<BemsDeviceRunHourlyCost> BemsDeviceRunHourlyCost { get; set; }
        public virtual DbSet<BemsDeviceType> BemsDeviceType { get; set; }
        public virtual DbSet<BemsDeviceTypeUsingEnergy> BemsDeviceTypeUsingEnergy { get; set; }
        public virtual DbSet<BemsEnergyConfigPercentMonth> BemsEnergyConfigPercentMonth { get; set; }
        public virtual DbSet<BemsEnergyConfigPercentWeek> BemsEnergyConfigPercentWeek { get; set; }
        public virtual DbSet<BemsEnergyCost> BemsEnergyCost { get; set; }
        public virtual DbSet<BemsEnergyDaily> BemsEnergyDaily { get; set; }
        public virtual DbSet<BemsEnergyDailyRegression> BemsEnergyDailyRegression { get; set; }
        public virtual DbSet<BemsEnergyDailyView> BemsEnergyDailyView { get; set; }
        public virtual DbSet<BemsEnergyGoalDaily> BemsEnergyGoalDaily { get; set; }
        public virtual DbSet<BemsFacilityType> BemsFacilityType { get; set; }
        public virtual DbSet<BemsFactorCo2> BemsFactorCo2 { get; set; }
        public virtual DbSet<BemsFactorToe> BemsFactorToe { get; set; }
        public virtual DbSet<BemsFaultDiagnosis> BemsFaultDiagnosis { get; set; }
        public virtual DbSet<BemsFaultServerityLevel> BemsFaultServerityLevel { get; set; }
        public virtual DbSet<BemsFaultType> BemsFaultType { get; set; }
        public virtual DbSet<BemsFloorPlan> BemsFloorPlan { get; set; }
        public virtual DbSet<BemsFloorStatus> BemsFloorStatus { get; set; }
        public virtual DbSet<BemsFormula> BemsFormula { get; set; }
        public virtual DbSet<BemsFormulaBase> BemsFormulaBase { get; set; }
        public virtual DbSet<BemsFormulaParameter> BemsFormulaParameter { get; set; }
        public virtual DbSet<BemsFormulaTable> BemsFormulaTable { get; set; }
        public virtual DbSet<BemsFormulaTableValue> BemsFormulaTableValue { get; set; }
        public virtual DbSet<BemsFuelType> BemsFuelType { get; set; }
        public virtual DbSet<BemsLoadsHourly> BemsLoadsHourly { get; set; }
        public virtual DbSet<BemsMeasureHistory> BemsMeasureHistory { get; set; }
        public virtual DbSet<BemsMeasureSchedule> BemsMeasureSchedule { get; set; }
        public virtual DbSet<BemsMeasureSchedulePoint> BemsMeasureSchedulePoint { get; set; }
        public virtual DbSet<BemsMonitoringPoint> BemsMonitoringPoint { get; set; }
        public virtual DbSet<BemsMonitoringPointBaseData> BemsMonitoringPointBaseData { get; set; }
        public virtual DbSet<BemsMonitoringPointConfig> BemsMonitoringPointConfig { get; set; }
        public virtual DbSet<BemsMonitoringPointHistory15min> BemsMonitoringPointHistory15min { get; set; }
        public virtual DbSet<BemsMonitoringPointHistory15minRawData> BemsMonitoringPointHistory15minRawData { get; set; }
        public virtual DbSet<BemsMonitoringPointHistoryDaily> BemsMonitoringPointHistoryDaily { get; set; }
        public virtual DbSet<BemsMonitoringPointHistoryHourly> BemsMonitoringPointHistoryHourly { get; set; }
        public virtual DbSet<BemsMonitoringPointToAnlaysisType> BemsMonitoringPointToAnlaysisType { get; set; }
        public virtual DbSet<BemsNoticePrice> BemsNoticePrice { get; set; }
        public virtual DbSet<BemsNoticePriceBase> BemsNoticePriceBase { get; set; }
        public virtual DbSet<BemsNoticePriceContractDataType> BemsNoticePriceContractDataType { get; set; }
        public virtual DbSet<BemsNoticePriceContractType> BemsNoticePriceContractType { get; set; }
        public virtual DbSet<BemsNoticePriceDetail> BemsNoticePriceDetail { get; set; }
        public virtual DbSet<BemsPeakFacility> BemsPeakFacility { get; set; }
        public virtual DbSet<BemsPeakHistory> BemsPeakHistory { get; set; }
        public virtual DbSet<BemsPeakHistoryDaily> BemsPeakHistoryDaily { get; set; }
        public virtual DbSet<BemsPeakInfo> BemsPeakInfo { get; set; }
        public virtual DbSet<BemsPeopleIncrease> BemsPeopleIncrease { get; set; }
        public virtual DbSet<BemsPriceCode> BemsPriceCode { get; set; }
        public virtual DbSet<BemsPriceFormula> BemsPriceFormula { get; set; }
        public virtual DbSet<BemsPriceMeta> BemsPriceMeta { get; set; }
        public virtual DbSet<BemsPriceType> BemsPriceType { get; set; }
        public virtual DbSet<BemsRentalRate> BemsRentalRate { get; set; }
        public virtual DbSet<BemsReportFormat> BemsReportFormat { get; set; }
        public virtual DbSet<BemsReportFormatContent> BemsReportFormatContent { get; set; }
        public virtual DbSet<BemsReportFormatToFacility> BemsReportFormatToFacility { get; set; }
        public virtual DbSet<BemsReportHistory> BemsReportHistory { get; set; }
        public virtual DbSet<BemsReportHistoryContent> BemsReportHistoryContent { get; set; }
        public virtual DbSet<BemsServiceType> BemsServiceType { get; set; }
        public virtual DbSet<BemsValueType> BemsValueType { get; set; }
        public virtual DbSet<BemsSitePrice> BemsSitePrice { get; set; }
        public virtual DbSet<BemsSitePriceHistory> BemsSitePriceHistory { get; set; }
        public virtual DbSet<BemsWeatherHourly> BemsWeatherHourly { get; set; }
        public virtual DbSet<BemsZone> BemsZone { get; set; }
        public virtual DbSet<BemsZoneActivate> BemsZoneActivate { get; set; }
        public virtual DbSet<BemsZoneActivateDaily> BemsZoneActivateDaily { get; set; }
        public virtual DbSet<CmAlarmAdmin> CmAlarmAdmin { get; set; }
        public virtual DbSet<CmAnnouncement> CmAnnouncement { get; set; }
        public virtual DbSet<CmBuilding> CmBuilding { get; set; }
        public virtual DbSet<CmBusinessField> CmBusinessField { get; set; }
        public virtual DbSet<CmCompany> CmCompany { get; set; }
        public virtual DbSet<CmCompanyType> CmCompanyType { get; set; }
        public virtual DbSet<CmDepartment> CmDepartment { get; set; }
        public virtual DbSet<CmFacility> CmFacility { get; set; }
        public virtual DbSet<CmFacilityFile> CmFacilityFile { get; set; }
        public virtual DbSet<CmFacilityTempSet> CmFacilityTempSet { get; set; }
        public virtual DbSet<CmFile> CmFile { get; set; }
        public virtual DbSet<CmFileCategory> CmFileCategory { get; set; }
        public virtual DbSet<CmFloor> CmFloor { get; set; }
        public virtual DbSet<CmFloorCode> CmFloorCode { get; set; }
        public virtual DbSet<CmGuideline> CmGuideline { get; set; }
        public virtual DbSet<CmHoliday> CmHoliday { get; set; }
        public virtual DbSet<CmHolidayCustom> CmHolidayCustom { get; set; }
        public virtual DbSet<CmHolidayWeekend> CmHolidayWeekend { get; set; }
        public virtual DbSet<CmMenu> CmMenu { get; set; }
        public virtual DbSet<CmPartner> CmPartner { get; set; }
        public virtual DbSet<CmPartnerType> CmPartnerType { get; set; }
        public virtual DbSet<CmPatrolCourse> CmPatrolCourse { get; set; }
        public virtual DbSet<CmPatrolCoursePos> CmPatrolCoursePos { get; set; }
        public virtual DbSet<CmPatrolGroup> CmPatrolGroup { get; set; }
        public virtual DbSet<CmPatrolGroupUser> CmPatrolGroupUser { get; set; }
        public virtual DbSet<CmPatrolHistory> CmPatrolHistory { get; set; }
        public virtual DbSet<CmPatrolHistoryPos> CmPatrolHistoryPos { get; set; }
        public virtual DbSet<CmPatrolPlan> CmPatrolPlan { get; set; }
        public virtual DbSet<CmPatrolPos> CmPatrolPos { get; set; }
        public virtual DbSet<CmPatrolSchedule> CmPatrolSchedule { get; set; }
        public virtual DbSet<CmPatrolType> CmPatrolType { get; set; }
        public virtual DbSet<CmPosition> CmPosition { get; set; }
        public virtual DbSet<CmServiceEnergyCalcDay> CmServiceEnergyCalcDay { get; set; }
        public virtual DbSet<CmServiceEnergyCalcMonth> CmServiceEnergyCalcMonth { get; set; }
        public virtual DbSet<CmSite> CmSite { get; set; }
        public virtual DbSet<CmSunrise> CmSunrise { get; set; }
        public virtual DbSet<CmSunriseSunset> CmSunriseSunset { get; set; }
        public virtual DbSet<CmUser> CmUser { get; set; }
        public virtual DbSet<CmUserGroup> CmUserGroup { get; set; }
        public virtual DbSet<CmUserGroupPermission> CmUserGroupPermission { get; set; }
        public virtual DbSet<CmUserLoginHistory> CmUserLoginHistory { get; set; }
        public virtual DbSet<CmUserToLicense> CmUserToLicense { get; set; }
        public virtual DbSet<CmZone> CmZone { get; set; }
        public virtual DbSet<CmZoneTempHumiSet> CmZoneTempHumiSet { get; set; }
        public virtual DbSet<Cols> Cols { get; set; }
        public virtual DbSet<FmsAccident> FmsAccident { get; set; }
        public virtual DbSet<FmsAccidentCodeType> FmsAccidentCodeType { get; set; }
        public virtual DbSet<FmsComplaints> FmsComplaints { get; set; }
        public virtual DbSet<FmsComplaintCodeType> FmsComplaintCodeType { get; set; }
        public virtual DbSet<FmsBudget> FmsBudget { get; set; }
        public virtual DbSet<FmsBudgetCodeClass> FmsBudgetCodeClass { get; set; }
        public virtual DbSet<FmsBudgetDetail> FmsBudgetDetail { get; set; }
        public virtual DbSet<FmsBudgetDetailExecution> FmsBudgetDetailExecution { get; set; }
        public virtual DbSet<FmsCompanyEstimationCodeClass> FmsCompanyEstimationCodeClass { get; set; }
        public virtual DbSet<FmsConstruction> FmsConstruction { get; set; }
        public virtual DbSet<FmsConstructionCodeProgress> FmsConstructionCodeProgress { get; set; }
        public virtual DbSet<FmsConstructionCodeType> FmsConstructionCodeType { get; set; }
        public virtual DbSet<FmsConstructionEstimation> FmsConstructionEstimation { get; set; }
        public virtual DbSet<FmsContract> FmsContract { get; set; }
        public virtual DbSet<FmsContractClass> FmsContractClass { get; set; }
        public virtual DbSet<FmsContractMethod> FmsContractMethod { get; set; }
        public virtual DbSet<FmsContractType> FmsContractType { get; set; }
        public virtual DbSet<FmsDailyCheckReport> FmsDailyCheckReport { get; set; }
        public virtual DbSet<FmsDailyReport> FmsDailyReport { get; set; }
        public virtual DbSet<FmsDailyStoredReleaseStatusView> FmsDailyStoredReleaseStatusView { get; set; }
        public virtual DbSet<FmsDrawing> FmsDrawing { get; set; }
        public virtual DbSet<FmsDrawingCodeGroup> FmsDrawingCodeGroup { get; set; }
        public virtual DbSet<FmsDrawingCodeType> FmsDrawingCodeType { get; set; }
        public virtual DbSet<FmsDrawingHistory> FmsDrawingHistory { get; set; }
        public virtual DbSet<FmsEnergyAnalysis> FmsEnergyAnalysis { get; set; }
        public virtual DbSet<FmsEquipment> FmsEquipment { get; set; }
        public virtual DbSet<FmsEquipmentCodeStateType> FmsEquipmentCodeStateType { get; set; }
        public virtual DbSet<FmsEquipmentCodeType> FmsEquipmentCodeType { get; set; }
        public virtual DbSet<FmsEquipmentHistory> FmsEquipmentHistory { get; set; }
        public virtual DbSet<FmsEquipmentRentInfo> FmsEquipmentRentInfo { get; set; }
        public virtual DbSet<FmsFacilityCheckItem> FmsFacilityCheckItem { get; set; }
        public virtual DbSet<FmsFacilityCodeClass> FmsFacilityCodeClass { get; set; }
        public virtual DbSet<FmsFacilityManual> FmsFacilityManual { get; set; }
        public virtual DbSet<FmsFacilityOperationItem> FmsFacilityOperationItem { get; set; }
        public virtual DbSet<FmsFacilityOperationReport> FmsFacilityOperationReport { get; set; }
        public virtual DbSet<FmsFacilityState> FmsFacilityState { get; set; }
        public virtual DbSet<FmsFacilityStateDetail> FmsFacilityStateDetail { get; set; }
        public virtual DbSet<CmSurvey> CmSurvey { get; set; }
        public virtual DbSet<FmsInvestmentCost> FmsInvestmentCost { get; set; }
        public virtual DbSet<FmsLicense> FmsLicense { get; set; }
        public virtual DbSet<FmsManual> FmsManual { get; set; }
        public virtual DbSet<FmsManualHistory> FmsManualHistory { get; set; }
        public virtual DbSet<FmsManualType> FmsManualType { get; set; }

        public virtual DbSet<FmsManualGroup> FmsManualGroup { get; set; }
        public virtual DbSet<FmsMaterial> FmsMaterial { get; set; }
        public virtual DbSet<FmsMaterialCarriedForward> FmsMaterialCarriedForward { get; set; }
        public virtual DbSet<FmsMaterialCodeAdjustmentType> FmsMaterialCodeAdjustmentType { get; set; }
        public virtual DbSet<FmsMaterialCodeClass> FmsMaterialCodeClass { get; set; }
        public virtual DbSet<FmsMaterialCodeLocation> FmsMaterialCodeLocation { get; set; }
        public virtual DbSet<FmsMaterialCodeProgress> FmsMaterialCodeProgress { get; set; }
        public virtual DbSet<FmsMaterialCodePurchaseType> FmsMaterialCodePurchaseType { get; set; }
        public virtual DbSet<FmsMaterialCodeReleaseType> FmsMaterialCodeReleaseType { get; set; }
        public virtual DbSet<FmsMaterialCodeType> FmsMaterialCodeType { get; set; }
        public virtual DbSet<FmsMaterialPurchaseOrder> FmsMaterialPurchaseOrder { get; set; }
        public virtual DbSet<FmsMaterialPurchaseOrderMaterial> FmsMaterialPurchaseOrderMaterial { get; set; }
        public virtual DbSet<FmsMaterialPurchaseRequest> FmsMaterialPurchaseRequest { get; set; }
        public virtual DbSet<FmsMaterialPurchaseRequestMaterial> FmsMaterialPurchaseRequestMaterial { get; set; }
        public virtual DbSet<FmsMaterialRelease> FmsMaterialRelease { get; set; }
        public virtual DbSet<FmsMaterialStored> FmsMaterialStored { get; set; }
        public virtual DbSet<FmsMaterialTradeCompany> FmsMaterialTradeCompany { get; set; }
        public virtual DbSet<FmsMaterialWarehouse> FmsMaterialWarehouse { get; set; }
        public virtual DbSet<FmsMonthlyReport> FmsMonthlyReport { get; set; }
        public virtual DbSet<FmsMonthKeyWork> FmsMonthKeyWork { get; set; }
        public virtual DbSet<FmsMonthlyStoredReleaseStatusView> FmsMonthlyStoredReleaseStatusView { get; set; }
        public virtual DbSet<FmsPaymentType> FmsPaymentType { get; set; }
        public virtual DbSet<FmsReport> FmsReport { get; set; }
        public virtual DbSet<FmsShortStockStatusView> FmsShortStockStatusView { get; set; }
        public virtual DbSet<FmsWeekKeyWork> FmsWeekKeyWork { get; set; }
        public virtual DbSet<FmsWorkCodeCauseClass> FmsWorkCodeCauseClass { get; set; }
        public virtual DbSet<FmsWorkCodeCycleUnit> FmsWorkCodeCycleUnit { get; set; }
        public virtual DbSet<FmsWorkCodeEmergency> FmsWorkCodeEmergency { get; set; }
        public virtual DbSet<FmsWorkCodeHolidayWorkType> FmsWorkCodeHolidayWorkType { get; set; }
        public virtual DbSet<FmsWorkCodeLegalInspectionAgency> FmsWorkCodeLegalInspectionAgency { get; set; }
        public virtual DbSet<FmsWorkCodeProgress> FmsWorkCodeProgress { get; set; }
        public virtual DbSet<FmsWorkCodeType> FmsWorkCodeType { get; set; }
        public virtual DbSet<FmsWorkOrder> FmsWorkOrder { get; set; }
        public virtual DbSet<FmsWorkOrderToFacility> FmsWorkOrderToFacility { get; set; }
        public virtual DbSet<FmsWorkRequest> FmsWorkRequest { get; set; }
        public virtual DbSet<FmsWorkRequestToFacility> FmsWorkRequestToFacility { get; set; }
        public virtual DbSet<FmsWorkResult> FmsWorkResult { get; set; }
        public virtual DbSet<FmsWorkResultCheckItem> FmsWorkResultCheckItem { get; set; }
        public virtual DbSet<FmsWorkResultCheckItemMaterial> FmsWorkResultCheckItemMaterial { get; set; }
        public virtual DbSet<FmsWorkResultFile> FmsWorkResultFile { get; set; }
        public virtual DbSet<FmsWorkResultLaw> FmsWorkResultLaw { get; set; }
        public virtual DbSet<FmsWorkResultToFacility> FmsWorkResultToFacility { get; set; }
        public virtual DbSet<FmsWorkSchedule> FmsWorkSchedule { get; set; }
        public virtual DbSet<FmsWorkScheduleToFacility> FmsWorkScheduleToFacility { get; set; }
        public virtual DbSet<WeatherDongNaeForecast> WeatherDongNaeForecast { get; set; }
        public virtual DbSet<WeatherDustSidoInfo> WeatherDustSidoInfo { get; set; }
        public virtual DbSet<WeatherShortTermForecast> WeatherShortTermForecast { get; set; }
        public virtual DbSet<WeatherShortTermNowValue> WeatherShortTermNowValue { get; set; }

        public virtual DbSet<Sitemap> Sitemap { get; set; }
        public virtual DbSet<SitemapAuth> SitemapAuth { get; set; }
        public virtual DbSet<SiteConfig> SiteConfig { get; set; }
        public virtual DbSet<CmTenant> CmTenant { get; set; }
        public virtual DbSet<FmsWorkCodeDetailType> FmsWorkCodeDetailType { get; set; }
        public virtual DbSet<FmsWorkRequestToAccident> FmsWorkRequestToAccident { get; set; }
        public virtual DbSet<FmsWorkRequestToComplaint> FmsWorkRequestToComplaint { get; set; }
        public virtual DbSet<FmsMaterialReleaseDetail> FmsMaterialReleaseDetail { get; set; }
        public virtual DbSet<SiteWeatherInfo> SiteWeatherInfo { get; set; }
        public virtual DbSet<WeatherRegionNxNy> WeatherRegionNxNy { get; set; }
        public virtual DbSet<FmsAlarmLog> FmsAlarmLog { get; set; }
        public virtual DbSet<FmsAlarmPoint> FmsAlarmPoint { get; set; }
        public virtual DbSet<MobileShortcut> MobileShortcut { get; set; }
        public virtual DbSet<CmRentalStatus> CmRentalStatus { get; set; }
        public virtual DbSet<CmOrganizationChartStatus> CmOrganizationChartStatus { get; set; }
        public virtual DbSet<CmCertificateStatus> CmCertificateStatus { get; set; }
        public virtual DbSet<CmLayout> CmLayout { get; set; }
        public virtual DbSet<CmInvestigation1> CmInvestigation1 { get; set; }
        public virtual DbSet<CmInvestigation2> CmInvestigation2 { get; set; }
        public virtual DbSet<CmInvestigation3> CmInvestigation3 { get; set; }
        public virtual DbSet<CmInvestigation1CodeGroup> CmInvestigation1CodeGroup { get; set; }
        public virtual DbSet<CmInvestigation1CodeType> CmInvestigation1CodeType { get; set; }
        public virtual DbSet<CmInvestigation2CodeGroup> CmInvestigation2CodeGroup { get; set; }
        public virtual DbSet<CmInvestigation2CodeType> CmInvestigation2CodeType { get; set; }
        public virtual DbSet<CmInvestigation3CodeGroup> CmInvestigation3CodeGroup { get; set; }
        public virtual DbSet<CmInvestigation3CodeType> CmInvestigation3CodeType { get; set; }

        public virtual DbSet<CmInvestigation1History> CmInvestigation1History { get; set; }
        public virtual DbSet<CmInvestigation2History> CmInvestigation2History { get; set; }
        public virtual DbSet<CmInvestigation3History> CmInvestigation3History { get; set; }


        protected override void OnModelCreating(ModelBuilder modelBuilder) {
            foreach (var foreignKey in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys())) {
                foreignKey.DeleteBehavior = DeleteBehavior.Restrict;
            }

            modelBuilder.Entity<BemsAlarmGroup>(entity => {
                entity.HasKey(e => new { e.SiteId, e.AlarmGroupId })
                    .HasName("PK__BemsAlar__9F06C6DFD20DDE73");

                entity.Property(e => e.AlarmGroupId).ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<BemsAlarmGroupUser>(entity => {
                entity.HasKey(e => new { e.SiteId, e.AlarmGroupId, e.UserId });
            });

            modelBuilder.Entity<BemsAlarmLog>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityTypeId, e.FacilityCode, e.PropertyId, e.FormulaId, e.CreatedDateTime })
                    .HasName("PK__BemsAlar__920ECD63CDC4C3D7");

                entity.HasOne(d => d.BemsAlarmSetting)
                    .WithMany(p => p.BemsAlarmLog)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityTypeId, d.FacilityCode, d.PropertyId, d.FormulaId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsAlarmLog_BemsAlarmSetting");
            });

            modelBuilder.Entity<BemsAlarmSetting>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityTypeId, e.FacilityCode, e.PropertyId, e.FormulaId });

                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsAlarmSetting)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsAlarmSetting_BemsFacilityType");

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsAlarmSetting)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsAlarmSetting_CmSite1");

                entity.HasOne(d => d.CmFacility)
                    .WithMany(p => p.BemsAlarmSetting)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsAlarmSetting_CmFacility");
            });

            modelBuilder.Entity<BemsAnalysisType>(entity => {
                entity.HasKey(e => new { e.SiteId, e.AnalysisType })
                    .HasName("PK__BemsAnal__248F415B95955FC7");

                entity.Property(e => e.AnalysisType)
                    .HasComment("고장 유형")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<BemsChartInfo>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityTypeId, e.ChartId });

                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsChartInfo)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsChartInfo_BemsFacilityType");

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsChartInfo)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsChartInfo_CmSite");
            });

            modelBuilder.Entity<BemsControlAhutempConfig>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityTypeId, e.FacilityCode });
            });

            modelBuilder.Entity<BemsControlGroup>(entity => {

                entity.Property(e => e.GroupId)
                    .HasComment("제어 그룸 ID")
                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<BemsControlGroupHistory>(entity => {
                entity.HasNoKey();

            });

            modelBuilder.Entity<BemsControlPointHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId, e.CreateDateTime })
                    .HasName("PK_BemsControlPointHistory_1");

                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsControlPointHistory)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsControlPointHistory_BemsFacilityType");

                entity.HasOne(d => d.BemsMonitoringPoint)
                    .WithMany(p => p.BemsControlPointHistory)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode, d.PropertyId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsControlPointHistory_BemsMonitoringPoint");
            });

            modelBuilder.Entity<BemsDevice>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.DeviceId })
                    .HasName("PK__BemsDevi__FCD3649C85423C27");

                entity.Property(e => e.DeviceId)
                    .HasComment("가동 설비고유번호")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.Name)
                    .IsUnicode(false)
                    .HasComment("가동 설비명");

                entity.Property(e => e.Nickname)
                    .IsUnicode(false)
                    .HasComment("설비별칭");

                entity.HasOne(d => d.DeviceType)
                    .WithMany(p => p.BemsDevice)
                    .HasForeignKey(d => d.DeviceTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDevice__BemsDeviceType");

                entity.HasOne(d => d.CmBuilding)
                    .WithMany(p => p.BemsDevice)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDevice__CmBuilding");

                entity.HasOne(d => d.BemsZone)
                    .WithMany(p => p.BemsDevice)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.ZoneId })
                    .HasConstraintName("FK__BemsDevice__BemsZone");
            });

            modelBuilder.Entity<BemsDeviceRunHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.DeviceId, e.ServiceTypeId, e.RunDate })
                    .HasName("PK__BemsDevi__7A33A9ABC319DE68");

                entity.HasOne(d => d.ServiceType)
                    .WithMany(p => p.BemsDeviceRunHistory)
                    .HasForeignKey(d => d.ServiceTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceRunHistory__BemsServiceType");

                entity.HasOne(d => d.BemsDevice)
                    .WithMany(p => p.BemsDeviceRunHistory)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.DeviceId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceRunHistory__BemsDevice");
            });

            modelBuilder.Entity<BemsDeviceRunHourly>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ServiceTypeId, e.RunDate })
                    .HasName("PK__BemsDevi__829656C703EED682");


                entity.HasOne(d => d.ServiceType)
                    .WithMany(p => p.BemsDeviceRunHourly)
                    .HasForeignKey(d => d.ServiceTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceRunHourly__BemsServiceType");

                entity.HasOne(d => d.CmBuilding)
                    .WithMany(p => p.BemsDeviceRunHourly)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceRunHourly__CmBuilding");
            });

            modelBuilder.Entity<BemsDeviceRunHourly2>(entity => {
                entity.HasNoKey();
            });

            modelBuilder.Entity<BemsDeviceRunHourlyCombine>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ServiceTypeId, e.RunDate, e.DeviceId })
                    .HasName("PK__BemsDevi__A1861F2637588945");

                entity.HasOne(d => d.BemsDevice)
                    .WithMany(p => p.BemsDeviceRunHourlyCombine)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.DeviceId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceRunHourlyCombine__BemsDevice");

                entity.HasOne(d => d.BemsDeviceRunHourly)
                    .WithMany(p => p.BemsDeviceRunHourlyCombine)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.ServiceTypeId, d.RunDate })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceRunHourlyCombine__BemsDeviceRunHourly");
            });

            modelBuilder.Entity<BemsDeviceRunHourlyCost>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ServiceTypeId, e.RunDate, e.FuelTypeId })
                    .HasName("PK__BemsDevi__6CA0524CFDB4ECBF");

                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsDeviceRunHourlyCost)
                    .HasForeignKey(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceRunHourlyCost__BemsFuelType");

                entity.HasOne(d => d.BemsDeviceRunHourly)
                    .WithMany(p => p.BemsDeviceRunHourlyCost)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.ServiceTypeId, d.RunDate })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceRunHourlyCost__BemsDeviceRunHourly");
            });

            modelBuilder.Entity<BemsDeviceType>(entity => {
                entity.HasKey(e => e.DeviceTypeId)
                    .HasName("PK__BemsDevi__07A6C7F64A52ADBE");

                entity.Property(e => e.DeviceTypeId)
                    .HasComment("가동 설비 타입")
                    .ValueGeneratedNever();

                entity.Property(e => e.Name)
                    .IsUnicode(false)
                    .HasComment("설비 타입명");

            });

            modelBuilder.Entity<BemsDeviceTypeUsingEnergy>(entity => {
                entity.HasKey(e => new { e.DeviceTypeId, e.FuelTypeId })
                    .HasName("PK__BemsDevi__67EE7915BB60B19E");

                entity.HasOne(d => d.DeviceType)
                    .WithMany(p => p.BemsDeviceTypeUsingEnergy)
                    .HasForeignKey(d => d.DeviceTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceTypeUsingEnergy__BemsDeviceType");

                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsDeviceTypeUsingEnergy)
                    .HasForeignKey(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsDeviceTypeUsingEnergy__BemsFuelType");

                entity.HasOne(d => d.BemsNoticePriceContractType)
                    .WithMany(p => p.BemsDeviceTypeUsingEnergy)
                    .HasForeignKey(d => new { d.FuelTypeId, d.ContractType })
                    .HasConstraintName("FK__BemsDeviceTypeUsingEnergy__BemsNoticePriceContractType");
            });

            modelBuilder.Entity<BemsEnergyConfigPercentMonth>(entity => {
                entity.HasKey(e => new { e.SiteId, e.Year, e.Month })
                    .HasName("PK__BemsEner__966DFBC7F1C7E4FF");

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsEnergyConfigPercentMonth)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsEnerg__SiteI__7954A4F6");
            });

            modelBuilder.Entity<BemsEnergyConfigPercentWeek>(entity => {
                entity.HasKey(e => new { e.SiteId, e.Year, e.Week })
                    .HasName("PK__BemsEner__38159A029BAEE931");

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsEnergyConfigPercentWeek)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsEnerg__SiteI__7C3111A1");
            });

            modelBuilder.Entity<BemsEnergyCost>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode })
                    .HasName("PK__BemsEner__D352CDB4E650C6B7");

                entity.HasOne(d => d.CmFacility)
                    .WithOne(p => p.BemsEnergyCost)
                    .HasForeignKey<BemsEnergyCost>(d => new { d.SiteId, d.FacilityCode })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsEnergyCost_CmFacility");
            });

            modelBuilder.Entity<BemsEnergyDaily>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ServiceTypeId, e.FuelTypeId, e.CreatedDate })
                    .HasName("PK__BemsEner__0C04940E9A573633");


                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsEnergyDaily)
                    .HasForeignKey(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsEnergyDaily__BemsFuelType");

                entity.HasOne(d => d.ServiceType)
                    .WithMany(p => p.BemsEnergyDaily)
                    .HasForeignKey(d => d.ServiceTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsEnergyDaily__BemsServiceType");

                entity.HasOne(d => d.CmBuilding)
                    .WithMany(p => p.BemsEnergyDaily)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsEnergyDaily__CmBuilding");
            });

            modelBuilder.Entity<BemsEnergyDailyRegression>(entity => {
                entity.HasKey(e => e.SiteId)
                    .HasName("PK__BemsEner__B9DCB963A8B309FB");

                entity.Property(e => e.SiteId).ValueGeneratedNever();

                entity.HasOne(d => d.Site)
                    .WithOne(p => p.BemsEnergyDailyRegression)
                    .HasForeignKey<BemsEnergyDailyRegression>(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsEnergyDailyRegression_CmSite");
            });

            modelBuilder.Entity<BemsEnergyDailyView>(entity => {
                entity.HasNoKey();

                entity.ToView("BemsEnergyDailyView");
            });

            modelBuilder.Entity<BemsEnergyGoalDaily>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.CreatedDate })
                    .HasName("PK__BemsEner__981C20D13E559644");

                entity.HasOne(d => d.CmBuilding)
                    .WithMany(p => p.BemsEnergyGoalDaily)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsEnergyGoalDaily__CmBuilding");
            });

            modelBuilder.Entity<BemsFacilityType>(entity => {

                entity.Property(e => e.FacilityTypeId)
                    .HasComment("설비유형 코드")
                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<BemsFactorCo2>(entity => {
                entity.HasKey(e => e.FuelTypeId)
                    .HasName("PK__BemsFact__048BEE371B4225DA");

                entity.Property(e => e.FuelTypeId)
                    .HasComment("연료 고유번호")
                    .ValueGeneratedNever();

                entity.HasOne(d => d.FuelType)
                    .WithOne(p => p.BemsFactorCo2)
                    .HasForeignKey<BemsFactorCo2>(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsFactorCo2__BemsFuelType");
            });

            modelBuilder.Entity<BemsFactorToe>(entity => {
                entity.HasKey(e => e.FuelTypeId)
                    .HasName("PK__BemsFact__048BEE3796BD6F37");

                entity.Property(e => e.FuelTypeId)
                    .HasComment("연료 고유번호")
                    .ValueGeneratedNever();

                entity.HasOne(d => d.FuelType)
                    .WithOne(p => p.BemsFactorToe)
                    .HasForeignKey<BemsFactorToe>(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsFactorToe__BemsFuelType");
            });

            modelBuilder.Entity<BemsFaultDiagnosis>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.DeviceId, e.CreatedDate })
                    .HasName("PK__BemsFaul__1B9B0ECA808FABBB");



                entity.HasOne(d => d.BemsFaultServerityLevel)
                    .WithMany(p => p.BemsFaultDiagnosis)
                    .HasForeignKey(d => new { d.FaultTypeId, d.ServerityLevel })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsFaultDiagnosis__BemsFaultServerityLevel");

                entity.HasOne(d => d.BemsDevice)
                    .WithMany(p => p.BemsFaultDiagnosis)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.DeviceId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsFaultDiagnosis__BemsDevice");
            });

            modelBuilder.Entity<BemsFaultServerityLevel>(entity => {
                entity.HasKey(e => new { e.FaultTypeId, e.ServerityLevel })
                    .HasName("PK__BemsFaul__6687901F7A797D16");

                entity.Property(e => e.Comment)
                    .IsUnicode(false)
                    .HasComment("비고사항");

                entity.HasOne(d => d.FaultType)
                    .WithMany(p => p.BemsFaultServerityLevel)
                    .HasForeignKey(d => d.FaultTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsFaultServerityLevel__BemsFaultType");
            });

            modelBuilder.Entity<BemsFaultType>(entity => {
                entity.HasKey(e => e.FaultTypeId)
                    .HasName("PK__BemsFaul__D60B7902A43B1742");

                entity.Property(e => e.FaultTypeId)
                    .HasComment("결함타입")
                    .ValueGeneratedNever();

                entity.Property(e => e.Name)
                    .IsUnicode(false)
                    .HasComment("결함명");
            });

            modelBuilder.Entity<BemsFloorPlan>(entity => {
                entity.HasNoKey();
            });

            modelBuilder.Entity<BemsFloorStatus>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FloorId, e.FloorName, e.ImageFileId, e.Xvalue, e.Yvalue, e.PropertyId });
            });

            modelBuilder.Entity<BemsFormula>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityTypeId, e.FacilityCode, e.FormulaId });

            });

            modelBuilder.Entity<BemsFormulaBase>(entity => {
                entity.HasKey(e => new { e.FacilityTypeId, e.FormulaId })
                    .HasName("PK__BemsForm__4ADF8146EDF21B51");

            });

            modelBuilder.Entity<BemsFormulaParameter>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.FormulaId, e.ParameterId })
                    .HasName("PK__BemsForm__501F395B0EB3B9B3");

                entity.Property(e => e.ParameterId)
                    .IsFixedLength()
                    .HasComment("수식에 사용된 파라메터 고유번호");

                entity.HasOne(d => d.CmFacility)
                    .WithMany(p => p.BemsFormulaParameter)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsFormulaParameter_CmFacility");

                entity.HasOne(d => d.BemsFormula)
                    .WithMany(p => p.BemsFormulaParameter)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityTypeId, d.FacilityCode, d.FormulaId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsFormulaParameter__BemsFormula");
            });

            modelBuilder.Entity<BemsFormulaTable>(entity => {
                entity.HasKey(e => e.TableId)
                    .HasName("PK__BemsForm__7D5F01EE8F24D18A");

                entity.Property(e => e.TableId)
                    .HasComment("수식 테이블 고유번호")
                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<BemsFormulaTableValue>(entity => {
                entity.HasKey(e => new { e.TableId, e.XValue });

                entity.HasOne(d => d.Table)
                    .WithMany(p => p.BemsFormulaTableValue)
                    .HasForeignKey(d => d.TableId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsFormulaTableValue__BemsFormulaTable");
            });

            modelBuilder.Entity<BemsFuelType>(entity => {
                entity.HasKey(e => e.FuelTypeId)
                    .HasName("PK__BemsFuel__2F4FDCEDAEA113DC");

                entity.Property(e => e.FuelTypeId)
                    .HasComment("연료 고유번호")
                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<BemsLoadsHourly>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ServiceTypeId, e.CreatedDate })
                    .HasName("PK__BemsLoad__66583043DDEFF303");

                entity.Property(e => e.RateOfWork)
                    .HasDefaultValueSql("((1))")
                    .HasComment("건물 가동율");

                entity.HasOne(d => d.ServiceType)
                    .WithMany(p => p.BemsLoadsHourly)
                    .HasForeignKey(d => d.ServiceTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsLoadsHourly__BemsServiceType");

                entity.HasOne(d => d.CmBuilding)
                    .WithMany(p => p.BemsLoadsHourly)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsLoadsHourly__CmBuilding");
            });

            modelBuilder.Entity<BemsMeasureHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.DeviceId, e.FuelTypeId, e.CreatedDate })
                    .HasName("PK__BemsMeas__71C7AA873DB3A288");


                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsMeasureHistory)
                    .HasForeignKey(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMeasureHistory__BemsFuelType");

                entity.HasOne(d => d.BemsDevice)
                    .WithMany(p => p.BemsMeasureHistory)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.DeviceId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMeasureHistory__BemsDevice");
            });

            modelBuilder.Entity<BemsMeasureSchedule>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ScheduleId })
                    .HasName("PK__BemsMeas__30141CD753D97A6F");

                entity.Property(e => e.ScheduleId)
                    .HasComment("검침계획번호")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.Name)
                    .IsUnicode(false)
                    .HasComment("검침계획명");

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsMeasureSchedule)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMeasureSchedule__CmSite");
            });

            modelBuilder.Entity<BemsMeasureSchedulePoint>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ScheduleId, e.DeviceId })
                    .HasName("PK__BemsMeas__950291F6984BC09A");

                entity.HasOne(d => d.BemsDevice)
                    .WithMany(p => p.BemsMeasureSchedulePoint)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.DeviceId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMeasureSchedulePoint__BemsDevice");
            });

            modelBuilder.Entity<BemsMonitoringPoint>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId })
                    .HasName("PK__BemsMoni__E72204137ACE99EE");



                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsMonitoringPoint)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsMonitoringPoint_BemsFacilityType");


                entity.HasOne(d => d.ValType)
                    .WithMany(p => p.BemsMonitoringPoint)
                    .HasForeignKey(d => d.ValueType)
                    .HasConstraintName("FK_BemsMonitoringPoint_BemsValueType");


                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsMonitoringPoint)
                    .HasForeignKey(d => d.FuelTypeId)
                    .HasConstraintName("FK__BemsMonitoringPoint__BemsFuelType");

                entity.HasOne(d => d.ServiceType)
                    .WithMany(p => p.BemsMonitoringPoint)
                    .HasForeignKey(d => d.ServiceTypeId)
                    .HasConstraintName("FK__BemsMonitoringPoint__BemsServiceType");

                entity.HasOne(d => d.CmBuilding)
                    .WithMany(p => p.BemsMonitoringPoint)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                    .HasConstraintName("FK__BemsMonitoringPoint__CmBuilding");

                entity.HasOne(d => d.CmFacility)
                    .WithMany(p => p.BemsMonitoringPoint)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsMonitoringPoint_CmFacility");

                entity.HasOne(d => d.CmFloor)
                    .WithMany(p => p.BemsMonitoringPoint)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.FloorId })
                    .HasConstraintName("FK__BemsMonitoringPoint__CmFloor");

                entity.HasOne(d => d.CmZone)
                    .WithMany(p => p.BemsMonitoringPoint)
                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.FloorId, d.ZoneId })
                    .HasConstraintName("FK__BemsMonitoringPoint__CmZone");
            });

            modelBuilder.Entity<BemsMonitoringPointBaseData>(entity => {
                entity.HasKey(e => new { e.FacilityTypeId, e.PropertyId });


                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsMonitoringPointBaseData)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointBaseData__BemsFacilityType");

                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsMonitoringPointBaseData)
                    .HasForeignKey(d => d.FuelTypeId)
                    .HasConstraintName("FK__BemsMonitoringPointBaseData__BemsFuelType");

                entity.HasOne(d => d.ServiceType)
                    .WithMany(p => p.BemsMonitoringPointBaseData)
                    .HasForeignKey(d => d.ServiceTypeId)
                    .HasConstraintName("FK__BemsMonitoringPointBaseData__BemsServiceType");
            });

            modelBuilder.Entity<BemsMonitoringPointConfig>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId });


                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsMonitoringPointConfig)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsMonitoringPointConfig_BemsFacilityType1");

                entity.HasOne(d => d.BemsMonitoringPoint)
                    .WithOne(p => p.BemsMonitoringPointConfig)
                    .HasForeignKey<BemsMonitoringPointConfig>(d => new { d.SiteId, d.FacilityCode, d.PropertyId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsMonitoringPointConfig_BemsMonitoringPoint");
            });

            modelBuilder.Entity<BemsMonitoringPointHistory15min>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId, e.CreatedDateTime })
                    .HasName("PK__BemsMoni__F1139AC41C6A2090");

                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsMonitoringPointHistory15min)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointHistory15min__BemsFacilityType");

                entity.HasOne(d => d.BemsMonitoringPoint)
                    .WithMany(p => p.BemsMonitoringPointHistory15min)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode, d.PropertyId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointHistory15min__BemsMonitoringPoint");
            });

            modelBuilder.Entity<BemsMonitoringPointHistory15minRawData>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId, e.CreatedDateTime });

                entity.HasIndex(e => e.SiteId)
                    .HasName("IX_BemsMonitoringPointHistory15minRawData");

                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsMonitoringPointHistory15minRawData)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointHistory15minRawData__BemsFacilityType");

                entity.HasOne(d => d.BemsMonitoringPoint)
                    .WithMany(p => p.BemsMonitoringPointHistory15minRawData)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode, d.PropertyId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointHistory15minRawData__BemsMonitoringPoint");
            });

            modelBuilder.Entity<BemsMonitoringPointHistoryDaily>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId, e.CreatedDateTime })
                    .HasName("PK__BemsMoni__F1139AC43CAC2FE3");


                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsMonitoringPointHistoryDaily)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointHistoryDaily__BemsFacilityType");

                entity.HasOne(d => d.BemsMonitoringPoint)
                    .WithMany(p => p.BemsMonitoringPointHistoryDaily)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode, d.PropertyId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointHistoryDaily__BemsMonitoringPoint");
            });

            modelBuilder.Entity<BemsMonitoringPointHistoryHourly>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId, e.CreatedDateTime })
                    .HasName("PK__BemsMoni__F1139AC470F7816A");

                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsMonitoringPointHistoryHourly)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointHistoryHourly__BemsFacilityType");

                entity.HasOne(d => d.BemsMonitoringPoint)
                    .WithMany(p => p.BemsMonitoringPointHistoryHourly)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode, d.PropertyId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointHistoryHourly__BemsMonitoringPoint");
            });

            modelBuilder.Entity<BemsMonitoringPointToAnlaysisType>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityTypeId, e.FacilityCode, e.PropertyId, e.AnalysisType })
                    .HasName("PK__BemsMoni__CFED929570D3FBE0");

                entity.HasOne(d => d.FacilityType)
                    .WithMany(p => p.BemsMonitoringPointToAnlaysisType)
                    .HasForeignKey(d => d.FacilityTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPointToAnlaysisType__BemsFacilityType");

                entity.HasOne(d => d.BemsAnalysisType)
                    .WithMany(p => p.BemsMonitoringPointToAnlaysisType)
                    .HasForeignKey(d => new { d.SiteId, d.AnalysisType })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPo__1372D2FE");

                entity.HasOne(d => d.BemsMonitoringPoint)
                    .WithMany(p => p.BemsMonitoringPointToAnlaysisType)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode, d.PropertyId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsMonitoringPo__155B1B70");
            });

            modelBuilder.Entity<BemsNoticePrice>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FuelTypeId, e.ApplyDate })
                    .HasName("PK__BemsNoti__B3C075E75C0AE7A6");

                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsNoticePrice)
                    .HasForeignKey(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsNoticePrice__BemsFuelType");

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsNoticePrice)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsNoticePrice__CmSite");
            });

            modelBuilder.Entity<BemsNoticePriceBase>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FuelTypeId, e.ApplyDate, e.ContractType })
                    .HasName("PK__BemsNoti__CB7092514F385CDB");

                entity.HasOne(d => d.BemsNoticePriceContractType)
                    .WithMany(p => p.BemsNoticePriceBase)
                    .HasForeignKey(d => new { d.FuelTypeId, d.ContractType })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsNoticePriceBase__BemsNoticePriceContractType");

                entity.HasOne(d => d.BemsNoticePrice)
                    .WithMany(p => p.BemsNoticePriceBase)
                    .HasForeignKey(d => new { d.SiteId, d.FuelTypeId, d.ApplyDate })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsNoticePriceBase__BemsNoticePrice");
            });

            modelBuilder.Entity<BemsNoticePriceContractDataType>(entity => {
                entity.HasNoKey();

                entity.Property(e => e.Name)
                    .IsUnicode(false)
                    .HasComment("계약명");
            });

            modelBuilder.Entity<BemsNoticePriceContractType>(entity => {
                entity.HasKey(e => new { e.FuelTypeId, e.ContractType })
                    .HasName("PK__BemsNoti__B46C584FEC1EA4CB");

                entity.Property(e => e.Name)
                    .IsUnicode(false)
                    .HasComment("계약명");

                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsNoticePriceContractType)
                    .HasForeignKey(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsNoticePriceContractType__BemsFuelType");
            });

            modelBuilder.Entity<BemsNoticePriceDetail>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FuelTypeId, e.ApplyDate, e.ContractType, e.DataId })
                    .HasName("PK__BemsNoti__FB4C0F54F0AD4487");



                entity.HasOne(d => d.BemsNoticePriceBase)
                    .WithMany(p => p.BemsNoticePriceDetail)
                    .HasForeignKey(d => new { d.SiteId, d.FuelTypeId, d.ApplyDate, d.ContractType })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__BemsNoticePriceDetail__BemsNoticePriceBase");
            });

            modelBuilder.Entity<BemsPeakFacility>(entity => {
                entity.HasKey(e => new { e.SiteId, e.MaxDateTime, e.FacilityCode })
                    .HasName("PK.BemsPeakFacility");

                entity.HasOne(d => d.CmFacility)
                    .WithMany(p => p.BemsPeakFacility)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPeakFacility_CmFacility");
            });

            modelBuilder.Entity<BemsPeakHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CreatedDateTime })
                    .HasName("PK_BemsPeakHIstory");

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsPeakHistory)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPeakHIstory_CmSite");
            });

            modelBuilder.Entity<BemsPeakHistoryDaily>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CreatedDateTime });
            });

            modelBuilder.Entity<BemsPeakInfo>(entity => {

                entity.Property(e => e.SiteId)
                    .HasComment("현장 고유번호")
                    .ValueGeneratedNever();

                entity.HasOne(d => d.Site)
                    .WithOne(p => p.BemsPeakInfo)
                    .HasForeignKey<BemsPeakInfo>(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPeakInfo_CmSite");
            });

            modelBuilder.Entity<BemsPeopleIncrease>(entity => {
                entity.HasKey(e => new { e.Date, e.SiteId });

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsPeopleIncrease)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPeopleIncrease_CmSite");
            });

            modelBuilder.Entity<BemsPriceCode>(entity => {
                entity.Property(e => e.PriceCode).IsUnicode(false);

                entity.Property(e => e.PriceCodeDesc).IsUnicode(false);

                entity.Property(e => e.Unit).IsUnicode(false);

                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsPriceCode)
                    .HasForeignKey(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPriceCode_BemsFuelType");
            });

            modelBuilder.Entity<BemsPriceFormula>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PriceTypeId, e.FacilityTypeId, e.FormulaId, e.FacilityCode });

                entity.HasOne(d => d.PriceType)
                    .WithMany(p => p.BemsPriceFormula)
                    .HasForeignKey(d => d.PriceTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPriceFormula_BemsPriceType");

                entity.HasOne(d => d.BemsFormula)
                    .WithMany(p => p.BemsPriceFormula)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityTypeId, d.FacilityCode, d.FormulaId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPriceFormula_BemsFormula");
            });

            modelBuilder.Entity<BemsPriceMeta>(entity => {
                entity.HasKey(e => new { e.PriceTypeId, e.PublishDate });

                entity.HasOne(d => d.PriceType)
                    .WithMany(p => p.BemsPriceMeta)
                    .HasForeignKey(d => d.PriceTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPriceMeta_BemsPriceType");
            });

            modelBuilder.Entity<BemsPriceType>(entity => {
                entity.HasKey(e => e.PriceTypeId)
                    .HasName("PK_BemsPriceType_1");

                entity.HasIndex(e => e.PriceTypeId)
                    .HasName("IX_BemsPriceType")
                    .IsUnique();

                entity.Property(e => e.PriceTypeId).ValueGeneratedNever();

                entity.Property(e => e.PriceTypeIdDesc).IsUnicode(false);

                entity.HasOne(d => d.FuelType)
                    .WithMany(p => p.BemsPriceType)
                    .HasForeignKey(d => d.FuelTypeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsPriceType_BemsFuelType1");
            });

            modelBuilder.Entity<BemsRentalRate>(entity => {
                entity.HasKey(e => new { e.Date, e.SiteId });

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.BemsRentalRate)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsRentalRate_CmSite");
            });

            modelBuilder.Entity<BemsReportFormat>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ReportFormatId });

                entity.HasOne(d => d.CmSite)
                    .WithMany(p => p.BemsReportFormat)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsReportFormat_CmSite");

                entity.HasOne(d => d.CmBusinessField)
                    .WithMany(p => p.BemsReportFormat)
                    .HasForeignKey(d => new { d.BusinessFieldId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsReportFormat_CmBusinessField");

                entity.Property(e => e.FormatName).IsUnicode(false);
            });

            modelBuilder.Entity<BemsReportFormatContent>(entity => {
                entity.HasKey(e => new {
                    e.SiteId,
                    e.ReportFormatId,
                    e.ContentId
                });

                entity.Property(e => e.Content).IsUnicode(false);

                entity.HasOne(d => d.BemsReportFormat)
                                .WithMany(p => p.BemsReportFormatContent)
                                .HasForeignKey(d => new {
                                    d.SiteId,
                                    d.ReportFormatId
                                })
                                .OnDelete(DeleteBehavior.Cascade)
                                .HasConstraintName("FK_BemsReportFormatContent_BemsReportFormatContent");

            });

            modelBuilder.Entity<BemsReportFormatToFacility>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ReportFormatId, e.FacilityCode });

                entity.HasOne(d => d.CmFacility)
                    .WithMany(p => p.BemsReportFormatToFacility)
                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BemsReportFormatToFacility_CmFacility");

                entity.HasOne(d => d.BemsReportFormat)
                                    .WithMany(p => p.BemsReportFormatToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.ReportFormatId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsReportFormatToFacility_BemsReportFormat");
            });

            modelBuilder.Entity<BemsReportHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.Seq });

                entity.Property(e => e.Confirm1).IsUnicode(false);

                entity.Property(e => e.Confirm2).IsUnicode(false);

                entity.Property(e => e.FormatName).IsUnicode(false);

                entity.Property(e => e.ReportName).IsUnicode(false);

                entity.Property(e => e.Writer).IsUnicode(false);

                entity.HasOne(d => d.CmFile)
                                    .WithMany(p => p.BemsReportHistory)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId })
                                    .HasConstraintName("FK_BemsReportHistory_CmFile");
            });

            modelBuilder.Entity<BemsReportHistoryContent>(entity => {
                entity.HasKey(e => new { e.SiteId, e.Seq, e.ContentId });

                entity.Property(e => e.Content).IsUnicode(false);

                entity.HasOne(d => d.BemsReportHistory)
                                    .WithMany(p => p.BemsReportHistoryContent)
                                    .HasForeignKey(d => new { d.SiteId, d.Seq })
                                    .OnDelete(DeleteBehavior.Cascade)
                                    .HasConstraintName("FK_BemsReportHistoryContent_BemsReportHistory");

            });

            modelBuilder.Entity<BemsServiceType>(entity => {
                entity.HasKey(e => e.ServiceTypeId)
                    .HasName("PK__BemsServ__0E5C2012D25A3DAA");

                entity.Property(e => e.ServiceTypeId)
                                    .HasComment("")
                                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<BemsSitePrice>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FuelTypeId, e.PriceTypeId, e.PriceCode });

                entity.Property(e => e.PriceCode).IsUnicode(false);

                entity.Property(e => e.UseYn).IsUnicode(false);

                entity.HasOne(d => d.FuelType)
                                    .WithMany(p => p.BemsSitePrice)
                                    .HasForeignKey(d => d.FuelTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsSitePrice_BemsFuelType");

                entity.HasOne(d => d.PriceCodeNavigation)
                                    .WithMany(p => p.BemsSitePrice)
                                    .HasForeignKey(d => d.PriceCode)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsSitePrice_BemsPriceCode");

                entity.HasOne(d => d.PriceType)
                                    .WithMany(p => p.BemsSitePrice)
                                    .HasForeignKey(d => d.PriceTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsSitePrice_BemsPriceType");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.BemsSitePrice)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsSitePrice_CmSite1");
            });

            modelBuilder.Entity<BemsSitePriceHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FuelTypeId, e.PriceTypeId, e.PriceCode, e.PayDate })
                    .HasName("PK_BemsSitePriceHistory_1");

                entity.Property(e => e.PriceCode).IsUnicode(false);

                entity.Property(e => e.PayDate).IsUnicode(false);

                entity.Property(e => e.PayCharge).IsUnicode(false);

                entity.Property(e => e.PriceValue).IsUnicode(false);

                entity.HasOne(d => d.FuelType)
                                    .WithMany(p => p.BemsSitePriceHistory)
                                    .HasForeignKey(d => d.FuelTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsSitePriceHistory_BemsFuelType");

                entity.HasOne(d => d.PriceCodeNavigation)
                                    .WithMany(p => p.BemsSitePriceHistory)
                                    .HasForeignKey(d => d.PriceCode)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsSitePriceHistory_BemsPriceCode");

                entity.HasOne(d => d.PriceType)
                                    .WithMany(p => p.BemsSitePriceHistory)
                                    .HasForeignKey(d => d.PriceTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsSitePriceHistory_BemsPriceType");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.BemsSitePriceHistory)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_BemsSitePriceHistory_CmSite");
            });

            modelBuilder.Entity<BemsWeatherHourly>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CreatedDate })
                    .HasName("PK__BemsWeat__F1B6EF84E39993F1");


                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.BemsWeatherHourly)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__BemsWeatherHourly__CmSite");
            });

            modelBuilder.Entity<BemsZone>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ZoneId })
                    .HasName("PK__BemsZone__58FA93D82DF67563");

                entity.Property(e => e.ZoneId)
                                    .HasComment("존 번호")
                                    .ValueGeneratedOnAdd();

                entity.Property(e => e.Name)
                                    .IsUnicode(false)
                                    .HasComment("존 명");

                entity.HasOne(d => d.CmBuilding)
                                    .WithMany(p => p.BemsZone)
                                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__BemsZone__CmBuilding");
            });

            modelBuilder.Entity<BemsZoneActivate>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ZoneId, e.ServiceTypeId })
                    .HasName("PK__BemsZone__FE223E228D7227B8");

                entity.HasOne(d => d.ServiceType)
                                    .WithMany(p => p.BemsZoneActivate)
                                    .HasForeignKey(d => d.ServiceTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__BemsZoneActivate__BemsServiceType");

                entity.HasOne(d => d.BemsZone)
                                    .WithMany(p => p.BemsZoneActivate)
                                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.ZoneId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__BemsZoneActivate__BemsZone");
            });

            modelBuilder.Entity<BemsZoneActivateDaily>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.ZoneId, e.ServiceTypeId, e.CreatedDate })
                    .HasName("PK__BemsZone__9056B8877CFE1068");





                entity.HasOne(d => d.BemsZoneActivate)
                                    .WithMany(p => p.BemsZoneActivateDaily)
                                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.ZoneId, d.ServiceTypeId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__BemsZoneActivateDaily__BemsZoneActivate");
            });

            modelBuilder.Entity<CmAlarmAdmin>(entity => {
                entity.HasKey(e => e.SiteId)
                    .HasName("PK__CmAlarmA__B9DCB9639249F478");

                entity.Property(e => e.SiteId).ValueGeneratedNever();
            });

            modelBuilder.Entity<CmAnnouncement>(entity => {
                entity.HasKey(e => new { e.SiteId, e.AnnouncementId });

                entity.Property(e => e.AnnouncementId)
                    .HasComment("공지사항 고유 번호")
                    .ValueGeneratedOnAdd();


                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.CmAnnouncement)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmAnnouncement_CmBusinessField");

                entity.HasOne(d => d.CmFile)
                                    .WithMany(p => p.CmAnnouncement)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId })
                                    .HasConstraintName("FK_CmAnnouncement_CmFile");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.CmAnnouncement)
                                    .HasForeignKey(d => d.RegisterUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmAnnouncement_CmUser");
            });

            modelBuilder.Entity<CmGuideline>(entity => {
                entity.HasKey(e => new { e.SiteId, e.GuidelineId });

                entity.Property(e => e.GuidelineId)
                    .HasComment("지침사항 고유 번호")
                    .ValueGeneratedOnAdd();


                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.CmGuideline)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmGuideline_CmBusinessField");

                entity.HasOne(d => d.CmFile)
                                    .WithMany(p => p.CmGuideline)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId })
                                    .HasConstraintName("FK_CmGuideline_CmFile");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.CmGuideline)
                                    .HasForeignKey(d => d.RegisterUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmGuideline_CmUser");
            });


            modelBuilder.Entity<CmBuilding>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId });

                entity.Property(e => e.BuildingId)
                    .HasComment("빌딩 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmBusinessField>(entity => {
                entity.HasKey(e => new { e.BusinessFieldId })
                    .HasName("PK__CmBusine__D557D6934E3BC926");

                entity.Property(e => e.BusinessFieldId)
                                    .HasComment("업무분야 고유번호")
                                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<CmCompany>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CompanyId })
                    .HasName("PK__CmCompan__6B05C8A97624D3C7");

                entity.Property(e => e.CompanyId)
                                    .HasComment("회사 고유번호")
                                    .ValueGeneratedOnAdd();

                entity.Property(e => e.AddressZip1)
                                    .IsFixedLength()
                                    .HasComment("우편번호 앞자리");

                entity.Property(e => e.AddressZip2)
                                    .IsFixedLength()
                                    .HasComment("우편번호 뒷자리");


                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmCompany)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmCompany__SiteI__336AA144");

                entity.HasOne(d => d.CmCompanyType)
                                    .WithMany(p => p.CmCompany)
                                    .HasForeignKey(d => new { d.CompanyTypeId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmCompany__345EC57D");
            });

            modelBuilder.Entity<CmCompanyType>(entity => {
                entity.HasKey(e => new { e.CompanyTypeId })
                    .HasName("PK__CmCompan__FCCA4958BBE3B86E");

                entity.Property(e => e.CompanyTypeId)
                                    .HasComment("회사 유형번호")
                                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<CmDepartment>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CompanyId, e.DepartmentId });

                entity.Property(e => e.DepartmentId)
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.CmCompany)
                                    .WithMany(p => p.CmDepartment)
                                    .HasForeignKey(d => new { d.SiteId, d.CompanyId });
            });

            modelBuilder.Entity<CmFacility>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode });
                entity.Property(e => e.FacilityCode)
                    .ValueGeneratedOnAdd();
                /*

                    entity.HasOne(d => d.CmFacilityNavigation)
                        .WithMany(p => p.InverseCmFacilityNavigation)
                        .HasForeignKey(d => new { d.SiteId, d.ParentFacilityCode });
                */
            });

            modelBuilder.Entity<CmFacilityFile>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FileId });

                entity.Property(e => e.FileId)
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.CmFacility)
                                    .WithMany(p => p.CmFacilityFile)
                                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                                    .OnDelete(DeleteBehavior.ClientSetNull);

                entity.HasOne(d => d.CmFile)
                                    .WithOne(p => p.CmFacilityFile)
                                    .HasForeignKey<CmFacilityFile>(d => new { d.SiteId, d.FileId })
                                    .OnDelete(DeleteBehavior.ClientSetNull);
            });

            modelBuilder.Entity<CmFacilityTempSet>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode });

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.CmFacilityTempSet)
                    .HasForeignKey(d => d.SiteId);

                entity.HasOne(d => d.CmFacility)
                                    .WithOne(p => p.CmFacilityTempSet)
                                    .HasForeignKey<CmFacilityTempSet>(d => new { d.SiteId, d.FacilityCode });
            });

            modelBuilder.Entity<CmFile>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FileId });

                entity.Property(e => e.FileId)
                    .HasComment("파일 고유번호")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.FileCategory)
                                    .WithMany(p => p.CmFile)
                                    .HasForeignKey(d => d.FileCategoryId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmFile__CmFileCategory");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmFile)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmFile__SiteId__2759D01A");
            });

            modelBuilder.Entity<CmFileCategory>(entity => {

                entity.Property(e => e.FileCategoryId)
                    .HasComment("파일 분류 번호")
                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<CmFloor>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.FloorId });

                entity.Property(e => e.FloorId).ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmFloorCode>(entity => {
                entity.HasKey(e => new { e.FloorCode });

                entity.Property(e => e.FloorCode).ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmRentalStatus>(entity => {
                entity.HasKey(e => new { e.SiteId, e.RentalStatusId });

                entity.Property(e => e.RentalStatusId).ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<CmOrganizationChartStatus>(entity => {
                entity.HasKey(e => new { e.SiteId, e.OrganizationChartStatusId });

                entity.Property(e => e.OrganizationChartStatusId).ValueGeneratedOnAdd();

            });
            modelBuilder.Entity<CmCertificateStatus>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CertificateStatusId });

                entity.Property(e => e.CertificateStatusId).ValueGeneratedOnAdd();

            });
            modelBuilder.Entity<CmLayout>(entity => {
                entity.HasKey(e => new { e.SiteId, e.LayoutId });

                entity.Property(e => e.LayoutId).ValueGeneratedOnAdd();

            });


            modelBuilder.Entity<CmHoliday>(entity => {
                entity.HasKey(e => new { e.SiteId, e.HolidayMonth, e.HolidayDay, e.IsLunar })
                    .HasName("PK__CmHolida__747A32C8CDCA1370");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmHoliday)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmHoliday__SiteI__0BB1B5A5");
            });

            modelBuilder.Entity<CmHolidayCustom>(entity => {
                entity.HasKey(e => new { e.SiteId, e.HolidayDate })
                    .HasName("PK__CmHolida__A6C664FE51F67E3C");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmHolidayCustom)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmHoliday__SiteI__10766AC2");
            });

            modelBuilder.Entity<CmHolidayWeekend>(entity => {
                entity.HasKey(e => e.SiteId)
                    .HasName("PK__CmHolida__B9DCB963785FEBFE");

                entity.Property(e => e.SiteId)
                                    .HasComment("현장 고유번호")
                                    .ValueGeneratedNever();

                entity.HasOne(d => d.Site)
                                    .WithOne(p => p.CmHolidayWeekend)
                                    .HasForeignKey<CmHolidayWeekend>(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmHoliday__SiteI__0D99FE17");
            });

            modelBuilder.Entity<CmMenu>(entity => {
                entity.HasKey(e => new { e.SiteId, e.MenuId });

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.CmMenu)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_CmMenu_CmSite");
            });

            modelBuilder.Entity<CmPartner>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PartnerId });

                entity.Property(e => e.PartnerId)
                    .HasComment("협력업체 고유번호")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.AddressZip1)
                                    .IsFixedLength()
                                    .HasComment("우편번호1");

                entity.Property(e => e.AddressZip2)
                                    .IsFixedLength()
                                    .HasComment("우편번호2");

                entity.HasOne(d => d.PartnerType)
                                    .WithMany(p => p.CmPartner)
                                    .HasForeignKey(d => d.PartnerTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPartnerType_CmPartner");

                entity.HasOne(d => d.BusinessField)
                                    .WithMany(p => p.CmPartner)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPartner_CmBusinessField");

            });

            modelBuilder.Entity<CmPartnerType>(entity => {
                entity.HasKey(e => e.PartnerTypeId)
                    .HasName("PK_CmPartnerType_1");

            });

            modelBuilder.Entity<CmPatrolCourse>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PatrolCourseId });

                entity.Property(e => e.PatrolCourseId)
                    .HasComment("순찰코스 고유번호")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmPatrolCourse)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolCourse_CmSite");
            });

            modelBuilder.Entity<CmPatrolCoursePos>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PatrolCourseId, e.BuildingId, e.FloorId, e.PosId });

                entity.HasOne(d => d.Site)
                    .WithMany(p => p.CmPatrolCoursePos)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_CmPatrolCoursePos_CmSite");

                entity.HasOne(d => d.CmPatrolCourse)
                                    .WithMany(p => p.CmPatrolCoursePos)
                                    .HasForeignKey(d => new { d.SiteId, d.PatrolCourseId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolCoursePos_CmPatrolCourse");
            });

            modelBuilder.Entity<CmPatrolGroup>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PatrolGroupId });

                entity.Property(e => e.PatrolGroupId)
                    .HasComment("순찰 그룹번호")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmPatrolGroup)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolGroup_CmSite");
            });

            modelBuilder.Entity<CmPatrolGroupUser>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PatrolGroupId, e.UserId });

                entity.HasOne(d => d.CmPatrolGroup)
                    .WithMany(p => p.CmPatrolGroupUser)
                    .HasForeignKey(d => new { d.SiteId, d.PatrolGroupId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_CmPatrolGroupUser_CmPatrolGroup");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.CmPatrolGroupUser)
                                    .HasForeignKey(d => d.UserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolGroupUser_CmUser");
            });

            modelBuilder.Entity<CmPatrolHistory>(entity => {
                entity.HasKey(e => e.PatrolHistoryId)
                    .HasName("PK_CmPatrolHistory_1");

                entity.Property(e => e.ResultDesc)
                                    .IsUnicode(false)
                                    .HasComment("특이 사항");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmPatrolHistory)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolHistory_CmSite");

                entity.HasOne(d => d.CmPatrolType)
                                    .WithMany(p => p.CmPatrolHistory)
                                    .HasForeignKey(d => new { d.SiteId, d.ResultTypeId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolHistory_CmPatrolType");

                entity.HasOne(d => d.S)
                                    .WithMany(p => p.CmPatrolHistory)
                                    .HasForeignKey(d => new { d.SiteId, d.ScheduleId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolHistory_CmPatrolSchedule");
            });

            modelBuilder.Entity<CmPatrolHistoryPos>(entity => {
                entity.HasKey(e => e.MId)
                    .HasName("PK_CmPatrolHistoryPos_1");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmPatrolHistoryPos)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolHistoryPos_CmSite");

                entity.HasOne(d => d.CmPatrolPos)
                                    .WithMany(p => p.CmPatrolHistoryPos)
                                    .HasForeignKey(d => new { d.SiteId, d.PosId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolHistoryPos_CmPatrolPos");

                entity.HasOne(d => d.CmPatrolType)
                                    .WithMany(p => p.CmPatrolHistoryPos)
                                    .HasForeignKey(d => new { d.SiteId, d.ResultType })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolHistoryPos_CmPatrolType");
            });

            modelBuilder.Entity<CmPatrolPlan>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PatrolPlanId });

                entity.Property(e => e.PatrolPlanId)
                    .HasComment("순찰 계획 고유번호")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.Name)
                                    .IsUnicode(false)
                                    .HasComment("순찰계획 명");

                entity.Property(e => e.PlanDesc)
                                    .IsUnicode(false)
                                    .HasComment("설명");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmPatrolPlan)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolPlan_CmSite");

                entity.HasOne(d => d.CmPatrolCourse)
                                    .WithMany(p => p.CmPatrolPlan)
                                    .HasForeignKey(d => new { d.SiteId, d.CourseId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolPlan_CmPatrolCourse");

                entity.HasOne(d => d.CmPatrolGroup)
                                    .WithMany(p => p.CmPatrolPlan)
                                    .HasForeignKey(d => new { d.SiteId, d.GroupId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolPlan_CmPatrolGroup");
            });

            modelBuilder.Entity<CmPatrolPos>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PosId })
                    .HasName("PK_CmPatrolPos_1");

                entity.HasIndex(e => new { e.SiteId, e.BuildingId, e.FloorId, e.Name })
                                    .HasName("UQ__CmPatrol__E9B4630E47C9E6E0")
                                    .IsUnique();

                entity.Property(e => e.PosId)
                                    .HasComment("지점 ID")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmPatrolPos)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolPos_CmSite");

                entity.HasOne(d => d.CmBuilding)
                                    .WithMany(p => p.CmPatrolPos)
                                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolPos_CmBuilding");

                entity.HasOne(d => d.CmFloor)
                                    .WithMany(p => p.CmPatrolPos)
                                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.FloorId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolPos_CmFloor");
            });

            modelBuilder.Entity<CmPatrolSchedule>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ScheduleId });

                entity.Property(e => e.ScheduleId)
                    .HasComment("순찰 일정 고유번호 ")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.Name)
                                    .IsUnicode(false)
                                    .HasComment("순찰 일정 명");

                entity.Property(e => e.ScheduleDesc)
                                    .IsUnicode(false)
                                    .HasComment("설명");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmPatrolSchedule)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolSchedule_CmSite");

                entity.HasOne(d => d.CmPatrolPlan)
                                    .WithMany(p => p.CmPatrolSchedule)
                                    .HasForeignKey(d => new { d.SiteId, d.PlanId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolSchedule_CmPatrolPlan");
            });

            modelBuilder.Entity<CmPatrolType>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PatrolTypeId });

                entity.HasIndex(e => new { e.SiteId, e.Name })
                    .HasName("UQ__CmPatrol__DEEBE12DD038AE1C")
                    .IsUnique();

                entity.Property(e => e.PatrolTypeId)
                                    .HasComment("순찰결과 코드")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmPatrolType)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmPatrolType_CmSite");
            });

            modelBuilder.Entity<CmPosition>(entity => {
                entity.HasKey(e => new { e.PositionId })
                    .HasName("PK__CmUserPo__3FD700C45CBED7EA");

                entity.Property(e => e.PositionId)
                                    .HasComment("직급 코드")
                                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmServiceEnergyCalcDay>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CalDate, e.ServiceTypeId });
            });

            modelBuilder.Entity<CmServiceEnergyCalcMonth>(entity => {
                entity.HasKey(e => new { e.CalDate, e.ServiceTypeId, e.SiteId });
            });

            modelBuilder.Entity<CmSite>(entity => {
                entity.HasKey(e => e.SiteId);

                entity.Property(e => e.SiteId)
                                    .ValueGeneratedOnAdd();

                entity.Property(e => e.AddressZip1)
                                    .IsFixedLength()
                                    .HasComment("현장 주소 우편번호 1");

                entity.Property(e => e.AddressZip2)
                                    .IsFixedLength()
                                    .HasComment("현장 주소 우편번호 2");


            });

            modelBuilder.Entity<CmSunrise>(entity => {
                entity.HasNoKey();

            });

            modelBuilder.Entity<CmSunriseSunset>(entity => {
                entity.HasNoKey();

            });

            modelBuilder.Entity<CmUser>(entity => {
                entity.Property(e => e.HomeZip1)
                    .IsUnicode(false)
                    .IsFixedLength()
                    .HasComment("사용자 우편번호 1");

                entity.Property(e => e.HomeZip2)
                                    .IsUnicode(false)
                                    .IsFixedLength()
                                    .HasComment("사용자 우편번호 2");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.CmUser)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .HasConstraintName("FK_CmUser_CmBusinessField");

                entity.HasOne(d => d.CmCompany)
                                    .WithMany(p => p.CmUser)
                                    .HasForeignKey(d => new { d.SiteId, d.CompanyId })
                                    .HasConstraintName("FK_CmUser_CmCompany");

                entity.HasOne(d => d.CmPosition)
                                    .WithMany(p => p.CmUser)
                                    .HasForeignKey(d => new { d.PositionId })
                                    .HasConstraintName("FK_CmUser_CmPosition");

                entity.HasOne(d => d.CmUserGroup)
                                    .WithMany(p => p.CmUser)
                                    .HasForeignKey(d => new { d.SiteId, d.UserGroupId })
                                    .HasConstraintName("FK_CmUser_CmUserGroup");

                entity.HasOne(d => d.CmDepartment)
                                    .WithMany(p => p.CmUser)
                                    .HasForeignKey(d => new { d.SiteId, d.CompanyId, d.DepartmentId })
                                    .HasConstraintName("FK_CmUser_CmDepartment");
            });

            modelBuilder.Entity<CmUserGroup>(entity => {
                entity.HasKey(e => new { e.SiteId, e.UserGroupId })
                    .HasName("PK__CmUserGr__089516558C3D97B5");

                entity.Property(e => e.UserGroupId)
                                    .HasComment("사용자 그룹 고유번호")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.CmUserGroup)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmUserGro__SiteI__53D770D6");
            });

            modelBuilder.Entity<CmUserGroupPermission>(entity => {
                entity.HasKey(e => new { e.SiteId, e.UserGroupId, e.MenuId })
                    .HasName("PK__CmUserGr__395C888790DBCBFC");

                entity.HasOne(d => d.CmUserGroup)
                                    .WithMany(p => p.CmUserGroupPermission)
                                    .HasForeignKey(d => new { d.SiteId, d.UserGroupId })
                                    .HasConstraintName("FK__CmUserGroupPermission__CmUserGroup");
            });

            modelBuilder.Entity<CmUserLoginHistory>(entity => {
                entity.HasKey(e => e.LoginHistoryId)
                    .HasName("PK_CmUserLoginHistory_1");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.CmUserLoginHistory)
                                    .HasForeignKey(d => d.UserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmUserLoginHistory_CmUser");
            });

            modelBuilder.Entity<CmUserToLicense>(entity => {
                entity.HasKey(e => new { e.SiteId, e.UserId, e.LicenseId })
                    .HasName("PK__CmUserTo__EBD6E3A7BBDAF8DE");

                entity.HasOne(d => d.FmsLicense)
                                    .WithMany(p => p.CmUserToLicense)
                                    .HasForeignKey(d => new { d.SiteId, d.LicenseId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmUserToLicense__FmsLicense");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.CmUserToLicense)
                                    .HasForeignKey(d => d.UserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmUserToLicense__CmUser");
            });

            modelBuilder.Entity<CmZone>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.FloorId, e.ZoneId });

                entity.Property(e => e.ZoneId).ValueGeneratedOnAdd();

                // entity.HasOne(d => d.CmBuilding)
                //     .WithMany(p => p.CmZone)
                //     .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                //     .OnDelete(DeleteBehavior.ClientSetNull)
                //     .HasConstraintName("FK__CmZone__CmBuilding");

                // entity.HasOne(d => d.CmFloor)
                //     .WithMany(p => p.CmZone)
                //     .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.FloorId })
                //     .OnDelete(DeleteBehavior.ClientSetNull)
                //     .HasConstraintName("FK__CmLocation__3DE82FB7");
            });

            modelBuilder.Entity<CmZoneTempHumiSet>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BuildingId, e.FloorId, e.ZoneId });





                entity.HasOne(d => d.Site)
                    .WithMany(p => p.CmZoneTempHumiSet)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_CmZoneTempHumiSet_CmSite");

                entity.HasOne(d => d.CmBuilding)
                                    .WithMany(p => p.CmZoneTempHumiSet)
                                    .HasForeignKey(d => new { d.SiteId, d.BuildingId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmZoneTempHumiSet_CmBuilding");

                entity.HasOne(d => d.CmFloor)
                                    .WithMany(p => p.CmZoneTempHumiSet)
                                    .HasForeignKey(d => new { d.SiteId, d.BuildingId, d.FloorId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmZoneTempHumiSet_CmFloor");

                entity.HasOne(d => d.CmZone)
                                    .WithOne(p => p.CmZoneTempHumiSet)
                                    .HasForeignKey<CmZoneTempHumiSet>(d => new { d.SiteId, d.BuildingId, d.FloorId, d.ZoneId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_CmZoneTempHumiSet_CmZone");
            });

            modelBuilder.Entity<Cols>(entity => {
                entity.HasNoKey();

                entity.ToView("Cols");

                entity.Property(e => e.ColLen).IsUnicode(false);

                entity.Property(e => e.ColTypeCode).IsUnicode(false);

                entity.Property(e => e.ColumnDesc).IsUnicode(false);

                entity.Property(e => e.ColumnName).IsUnicode(false);

                entity.Property(e => e.IsPk).IsUnicode(false);

                entity.Property(e => e.SystemDivision).IsUnicode(false);

                entity.Property(e => e.TableDesc).IsUnicode(false);

                entity.Property(e => e.TableName).IsUnicode(false);

                entity.Property(e => e.TableOrder).IsUnicode(false);
            });

            modelBuilder.Entity<FmsAccident>(entity => {
                entity.HasKey(e => new { e.SiteId, e.AccidentId });

                entity.Property(e => e.AccidentId)
                    .HasComment("사고 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsAccidentCodeType>(entity => {
                entity.HasKey(e => new { e.AccidentTypeId });

                entity.Property(e => e.AccidentTypeId)
                    .HasComment("사고 코드")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.IsUse)
                                    .HasDefaultValueSql("((1))")
                                    .HasComment("사용 유무");

            });

            modelBuilder.Entity<FmsComplaints>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ComplaintId });

                entity.Property(e => e.ComplaintId)
                    .HasComment("민원 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsComplaintCodeType>(entity => {
                entity.HasKey(e => new { e.ComplaintTypeId });

                entity.Property(e => e.ComplaintTypeId)
                    .HasComment("민원 코드")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.IsUse)
                                    .HasDefaultValueSql("((1))")
                                    .HasComment("사용 유무");

            });

            modelBuilder.Entity<FmsBudget>(entity => {
                entity.HasKey(e => new { e.SiteId, e.Year })
                    .HasName("PK_FmsBudget_2");

            });

            modelBuilder.Entity<FmsBudgetCodeClass>(entity => {
                entity.HasKey(e => new { e.SiteId, e.BudgetClassId });

                entity.Property(e => e.BudgetClassId)
                    .HasComment("예산편성 분류 코드")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.IsUse)
                                    .HasDefaultValueSql("((1))")
                                    .HasComment("사용유무");

            });

            modelBuilder.Entity<FmsBudgetDetail>(entity => {
                entity.HasKey(e => new { e.SiteId, e.Year, e.BudgetClassId, e.ParentBudgetClassId })
                    .HasName("PK_FmsBudget");

                entity.Property(e => e.IsUse)
                                    .HasDefaultValueSql("((1))")
                                    .HasComment("사용유무");

                entity.HasOne(d => d.FmsBudgetCodeClass)
                                    .WithMany(p => p.FmsBudgetDetail)
                                    .HasForeignKey(d => new { d.SiteId, d.BudgetClassId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsBudgetDetail_FmsBudgetCodeClass");

                entity.HasOne(d => d.FmsBudget)
                                    .WithMany(p => p.FmsBudgetDetail)
                                    .HasForeignKey(d => new { d.SiteId, d.Year })
                                    .HasConstraintName("FK_FmsBudgetDetail_FmsBudget");
            });

            modelBuilder.Entity<FmsBudgetDetailExecution>(entity => {
                entity.HasKey(e => new { e.SiteId, e.Year, e.BudgetClassId, e.ParentBudgetClassId, e.Month });

                entity.HasOne(d => d.FmsBudgetDetail)
                    .WithMany(p => p.FmsBudgetDetailExecution)
                    .HasForeignKey(d => new { d.SiteId, d.Year, d.BudgetClassId, d.ParentBudgetClassId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_FmsBudgetDetailExecution_FmsBudgetDetail");
            });

            modelBuilder.Entity<FmsCompanyEstimationCodeClass>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CompanyEstimationClassId });

                entity.Property(e => e.CompanyEstimationClassId)
                    .HasComment("평가결과 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsConstruction>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ConstructionId });

                entity.Property(e => e.ConstructionId)
                    .HasComment("공사 계약 고유번호")
                    .ValueGeneratedOnAdd();




                entity.HasOne(d => d.Progress)
                                    .WithMany(p => p.FmsConstruction)
                                    .HasForeignKey(d => d.ProgressId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsConstruction_FmsConstructionCodeProgress");

                entity.HasOne(d => d.FmsConstructionCodeType)
                                    .WithMany(p => p.FmsConstruction)
                                    .HasForeignKey(d => new { d.SiteId, d.ConstructionTypeId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsConstruction_FmsConstructionCodeType");

                entity.HasOne(d => d.CmFile)
                                    .WithMany(p => p.FmsConstructionCmFile)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId1 })
                                    .HasConstraintName("FK_FmsConstruction_CmFile1");

                entity.HasOne(d => d.CmFileNavigation)
                                    .WithMany(p => p.FmsConstructionCmFileNavigation)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId2 })
                                    .HasConstraintName("FK_FmsConstruction_CmFile2");

                entity.HasOne(d => d.CmFile1)
                                    .WithMany(p => p.FmsConstructionCmFile1)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId3 })
                                    .HasConstraintName("FK_FmsConstruction_CmFile3");

                entity.HasOne(d => d.CmPartner)
                                    .WithMany(p => p.FmsConstruction)
                                    .HasForeignKey(d => new { d.SiteId, d.PartnerId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsConstruction_CmPartner");
            });

            modelBuilder.Entity<FmsConstructionCodeProgress>(entity => {

                entity.Property(e => e.ProgressId)
                    .HasComment("진행상태 코드")
                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<FmsConstructionCodeType>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ConstructionTypeId });

                entity.Property(e => e.ConstructionTypeId)
                    .HasComment("공사타입 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsConstructionEstimation>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ConstructionId })
                    .HasName("PK_FmsConstructionEstimation_1");





                entity.HasOne(d => d.FmsConstruction)
                                    .WithOne(p => p.FmsConstructionEstimation)
                                    .HasForeignKey<FmsConstructionEstimation>(d => new { d.SiteId, d.ConstructionId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsConstructionEstimation_FmsConstruction");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsConstructionEstimation)
                                    .HasForeignKey(d => d.EstimateUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsConstructionEstimation_CmUser");
            });

            modelBuilder.Entity<FmsContract>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ContractId });

                entity.Property(e => e.ContractId)
                    .HasComment("계약체결 고유번호")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.PartnerType)
                                    .WithMany(p => p.FmsContract)
                                    .HasForeignKey(d => d.PartnerTypeId)
                                    .HasConstraintName("FK_FmsContract_CmPartnerType");

                entity.HasOne(d => d.FmsContractClass)
                                    .WithMany(p => p.FmsContract)
                                    .HasForeignKey(d => new { d.ContractClassId })
                                    .HasConstraintName("FK_FmsContract_FmsContractClass");

                entity.HasOne(d => d.FmsContractMethod)
                                    .WithMany(p => p.FmsContract)
                                    .HasForeignKey(d => new { d.ContractMethodId })
                                    .HasConstraintName("FK_FmsContract_FmsContractMethod");

                entity.HasOne(d => d.FmsContractType)
                                    .WithMany(p => p.FmsContract)
                                    .HasForeignKey(d => new { d.ContractTypeId })
                                    .HasConstraintName("FK_FmsContract_FmsContractType");

                entity.HasOne(d => d.CmPartner)
                                    .WithMany(p => p.FmsContract)
                                    .HasForeignKey(d => new { d.SiteId, d.PartnerId })
                                    .HasConstraintName("FK_FmsContract_CmPartner");

                entity.HasOne(d => d.FmsPaymentType)
                                    .WithMany(p => p.FmsContract)
                                    .HasForeignKey(d => new { d.PaymentTypeId })
                                    .HasConstraintName("FK_FmsContract_FmsPaymentType");

                // entity.HasOne(d => d.CmFile)
                //                     .WithMany(p => p.FmsContract)
                //                     .HasForeignKey(d => new { d.SiteId, d.FileId })
                //                     .HasConstraintName("FK_FmsContract_CmFile");
            });

            modelBuilder.Entity<FmsContractClass>(entity => {
                entity.HasKey(e => new { e.ContractClassId });

                entity.Property(e => e.ContractClassId)
                    .HasComment("근무형태 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsContractMethod>(entity => {
                entity.HasKey(e => new { e.ContractMethodId });

                entity.Property(e => e.ContractMethodId)
                    .HasComment("계약 방법 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsContractType>(entity => {
                entity.HasKey(e => new { e.ContractTypeId });

                entity.Property(e => e.ContractTypeId)
                    .HasComment("계약 종류 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsDailyCheckReport>(entity => {
                entity.HasKey(e => new { e.SiteId, e.DailyCheckReportId });

                entity.Property(e => e.DailyCheckReportId)
                    .HasComment("")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsDailyCheckReport)
                                    .HasForeignKey(d => d.RegisterUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsDailyCheckReport_CmUser");
            });

            modelBuilder.Entity<FmsMonthlyReport>(entity => {
                entity.HasKey(e => new { e.SiteId, e.AddDate, e.BusinessFieldId });
            });

            modelBuilder.Entity<FmsDailyReport>(entity => {
                entity.HasKey(e => new { e.SiteId, e.AddDate, e.BusinessFieldId });

                entity.Property(e => e.Datas)
                    .IsUnicode(false)
                    .HasComment("추가내용");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsDailyReport)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsDailyReport_CmBusinessField");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsDailyReport)
                                    .HasForeignKey(d => d.RegisterUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsDailyReport_CmUser");
            });


            modelBuilder.Entity<FmsDailyStoredReleaseStatusView>(entity => {
                entity.HasNoKey();

                entity.ToView("FmsDailyStoredReleaseStatusView");
            });

            modelBuilder.Entity<FmsDrawing>(entity => {
                entity.HasKey(e => new { e.SiteId, e.DrawingId });

                entity.Property(e => e.DrawingId)
                    .HasComment("도면 고유 번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsDrawingCodeGroup>(entity => {
                entity.HasKey(e => new { e.DrawingGroupId });

                entity.Property(e => e.DrawingGroupId)
                    .HasComment("도면 그룹 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsDrawingCodeType>(entity => {
                entity.HasKey(e => new { e.DrawingTypeId });

                entity.Property(e => e.DrawingTypeId)
                    .HasComment("도면 유형 고유번호")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsDrawingHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.DrawingId, e.HistoryId });

                entity.Property(e => e.HistoryId)
                    .HasComment("설비 도면 수정 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsEquipment>(entity => {
                entity.HasKey(e => new { e.SiteId, e.EquipmentId });

                entity.Property(e => e.EquipmentId)
                    .HasComment("공기구 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsEquipmentCodeStateType>(entity => {

                entity.Property(e => e.EquipmentStateTypeId)
                    .HasComment("공기구상태코드")
                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<FmsEquipmentCodeType>(entity => {
                entity.HasKey(e => new { e.EquipmentTypeId });

                entity.Property(e => e.EquipmentTypeId)
                    .HasComment("공기구 유형 고유번호")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsEquipmentHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.EquipmentHistoryId, e.EquipmentId });

                entity.Property(e => e.EquipmentHistoryId)
                    .HasComment("공기구 사용이력 고유번호")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.CurrentRentCount)
                                    .HasDefaultValueSql("((0))")
                                    .HasComment("현재 대여중인 수량");

                entity.Property(e => e.CurrentStockCount)
                                    .HasDefaultValueSql("((0))")
                                    .HasComment("현재보유수량(byCase)");

                entity.Property(e => e.LossCount)
                                    .HasDefaultValueSql("((0))")
                                    .HasComment("손망실수량(byCase)");

                entity.Property(e => e.RentCount)
                                    .HasDefaultValueSql("((0))")
                                    .HasComment("대여수량(byCase)");

                entity.Property(e => e.StoredCount)
                                    .HasDefaultValueSql("((0))")
                                    .HasComment("입고수량(byCase)");

                entity.Property(e => e.TotalStockCount)
                                    .HasDefaultValueSql("((0))")
                                    .HasComment("전체수량(byCase)");

                entity.HasOne(d => d.EquipmentStateType)
                                    .WithMany(p => p.FmsEquipmentHistory)
                                    .HasForeignKey(d => d.EquipmentStateTypeId)
                                    .HasConstraintName("FK_FmsEquipmentHistory_FmsEquipmentCodeStateType");

                entity.HasOne(d => d.FmsEquipment)
                                    .WithMany(p => p.FmsEquipmentHistory)
                                    .HasForeignKey(d => new { d.SiteId, d.EquipmentId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsEquipmentHistory_FmsEquipment");

                entity.HasOne(d => d.FmsEquipmentRentInfo)
                                    .WithMany(p => p.FmsEquipmentHistory)
                                    .HasForeignKey(d => new { d.SiteId, d.EquipmentRentId })
                                    .OnDelete(DeleteBehavior.Cascade)
                                    .HasConstraintName("FK_FmsEquipmentHistory_FmsEquipmentRentInfo");
            });

            modelBuilder.Entity<FmsEquipmentRentInfo>(entity => {
                entity.HasKey(e => new { e.SiteId, e.EquipmentRentId });

                entity.Property(e => e.EquipmentRentId)
                    .HasComment("공기구 대여 고유번호")
                    .ValueGeneratedOnAdd();

                entity.Property(e => e.RegisterDate)
                                    .IsFixedLength()
                                    .HasComment("등록일");

                entity.HasOne(d => d.EquipmentStateType)
                                    .WithMany(p => p.FmsEquipmentRentInfo)
                                    .HasForeignKey(d => d.EquipmentStateTypeId)
                                    .HasConstraintName("FK_FmsEquipmentRentInfo_FmsEquipmentCodeStateType");
            });

            modelBuilder.Entity<FmsFacilityCheckItem>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.CheckItemId });

                entity.Property(e => e.CheckItemId)
                    .HasComment("")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.WorkType)
                                    .WithMany(p => p.FmsFacilityCheckItem)
                                    .HasForeignKey(d => d.WorkTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsFacilityCheckItem__FmsWorkCodeWorkType");

                entity.HasOne(d => d.FmsWorkCodeCycleUnit)
                                    .WithMany(p => p.FmsFacilityCheckItem)
                                    .HasForeignKey(d => new { d.SiteId, d.CycleUnitId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsFacilityCheckItem__FmsWorkCodeCycleUnit");
            });

            modelBuilder.Entity<FmsFacilityCodeClass>(entity => {
                entity.HasKey(e => new { e.FacilityClassId });
                entity.Property(e => e.FacilityClassId)
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsFacilityManual>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.ManualId })
                    .HasName("PK__CmFacili__D40F16B497254F13");

                entity.Property(e => e.ManualId)
                                    .HasComment("매뉴얼 고유번호")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsFacilityManual)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmFacilityManual__7BE56230");

                entity.HasOne(d => d.CmFacility)
                                    .WithMany(p => p.FmsFacilityManual)
                                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__CmFacilityManual__79FD19BE");
            });

            modelBuilder.Entity<FmsFacilityOperationItem>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ItemId })
                    .HasName("PK__FmsFacil__1EFB515B743CF743");

                entity.Property(e => e.ItemId)
                                    .HasComment("")
                                    .ValueGeneratedOnAdd();


                entity.HasOne(d => d.CmFacility)
                                    .WithOne(p => p.FmsFacilityOperationItem)
                                    .HasForeignKey<FmsFacilityOperationItem>(d => new { d.SiteId, d.ItemId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsFacilityOpera__725BF7F6");
            });

            modelBuilder.Entity<FmsFacilityOperationReport>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityOperationReportId });

                entity.Property(e => e.FacilityOperationReportId)
                    .HasComment("")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsFacilityOperationReport)
                                    .HasForeignKey(d => d.RegisterUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsFacilityOperationReport_CmUser");
            });

            modelBuilder.Entity<FmsInvestmentCost>(entity => {
                entity.HasKey(e => new { e.SiteId, e.InsvestmentCostId });

                entity.Property(e => e.InsvestmentCostId)
                    .HasComment("투자비 항목 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsLicense>(entity => {
                entity.HasKey(e => new { e.SiteId, e.LicenseId })
                    .HasName("PK__FmsLicen__8EF1D96BBE94D1BE");

                entity.Property(e => e.LicenseId)
                                    .HasComment("")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsLicense)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsLicense__CmSite");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsLicense)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .HasConstraintName("FK__FmsLicense__CmBusinessField");
            });

            modelBuilder.Entity<FmsManual>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ManualId });

                entity.Property(e => e.ManualId)
                    .HasComment("매뉴얼 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsManualHistory>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ManualId, e.HistoryId });

                entity.Property(e => e.HistoryId)
                    .HasComment("매뉴얼 이력 구분 번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsManualType>(entity => {
                entity.HasKey(e => new { e.ManualTypeId });

                entity.Property(e => e.ManualTypeId)
                    .HasComment("매뉴얼 유형 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsManualGroup>(entity => {
                entity.HasKey(e => new { e.ManualGroupId });

                entity.Property(e => e.ManualGroupId)
                    .HasComment("매뉴얼 분류 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsMaterial>(entity => {
                entity.HasKey(e => new { e.SiteId, e.MaterialId });
                entity.Property(e => e.MaterialId)
                    .ValueGeneratedOnAdd();
                /*
                    entity.HasOne(d => d.Site)
                        .WithMany(p => p.FmsMaterial)
                        .HasForeignKey(d => d.SiteId);

                    entity.HasOne(d => d.CmBusinessField)
                        .WithMany(p => p.FmsMaterial)
                        .HasForeignKey(d => new { d.BusinessFieldId });

                    entity.HasOne(d => d.CmFile)
                        .WithMany(p => p.FmsMaterial)
                        .HasForeignKey(d => new { d.SiteId, d.ImageFileId });

                    entity.HasOne(d => d.FmsMaterialCodeLocation)
                        .WithMany(p => p.FmsMaterial)
                        .HasForeignKey(d => new { d.SiteId, d.LocationId })
                        .HasConstraintName("FK_FmsMaterial_FmsMaterialCodeLocation");

                    entity.HasOne(d => d.FmsMaterialCodeType)
                        .WithMany(p => p.FmsMaterial)
                        .HasForeignKey(d => new { d.SiteId, d.MaterialTypeId });

                    entity.HasOne(d => d.FmsMaterialTradeCompany)
                        .WithMany(p => p.FmsMaterial)
                        .HasForeignKey(d => new { d.SiteId, d.TradeCompanyId });

                    entity.HasOne(d => d.FmsMaterialWarehouse)
                        .WithMany(p => p.FmsMaterial)
                        .HasForeignKey(d => new { d.SiteId, d.WarehouseId });
                */
            });

            modelBuilder.Entity<FmsMaterialCarriedForward>(entity => {
                entity.HasKey(e => new { e.SiteId, e.ClosedDate, e.BusinessFieldId, e.WarehouseId, e.MaterialId })
                    .HasName("PK__FmsMater__6ABE9B82E5F38B14");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsMaterialCarriedForward)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialCarriedForward__CmSite");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsMaterialCarriedForward)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialCarriedForward__CmBusinessField");
            });

            modelBuilder.Entity<FmsMaterialCodeAdjustmentType>(entity => {

                entity.Property(e => e.AdjustmentTypeId)
                    .HasComment("정산 코드")
                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<FmsMaterialCodeClass>(entity => {
                entity.HasKey(e => new { e.MaterialClassId });
                entity.Property(e => e.MaterialClassId)
                    .ValueGeneratedOnAdd();
                /*
                    entity.HasOne(d => d.Site)
                        .WithMany(p => p.FmsMaterialCodeClass)
                        .HasForeignKey(d => d.SiteId);
                */
            });

            modelBuilder.Entity<FmsMaterialCodeLocation>(entity => {
                entity.HasKey(e => new { e.SiteId, e.LocationId })
                    .HasName("PK__FmsMater__D7A3532AFDD365FE");

                entity.Property(e => e.LocationId)
                                    .HasComment("보관창고 코드")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsMaterialCodeLocation)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialCodeLocation__CmSite");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsMaterialCodeLocation)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialCodeLocation__CmBusinessField");
            });

            modelBuilder.Entity<FmsMaterialCodeProgress>(entity => {
                entity.HasKey(e => e.ProgressId)
                    .HasName("PK__FmsMater__1B39A956C02E6627");

                entity.Property(e => e.ProgressId)
                                    .HasComment("진행 상태 코드")
                                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<FmsMaterialCodePurchaseType>(entity => {

            });

            modelBuilder.Entity<FmsMaterialCodeReleaseType>(entity => {
                entity.HasKey(e => e.ReleaseTypeId)
                    .HasName("PK__FmsMater__A0AD7C35E7E3B491");

                entity.Property(e => e.ReleaseTypeId)
                                    .HasComment("작업출고 코드")
                                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<FmsMaterialCodeType>(entity => {
                entity.HasKey(e => new { e.MaterialTypeId })
                    .HasName("PK__FmsMater__58BEA2DE75682874");

                entity.Property(e => e.MaterialTypeId)
                                    .HasComment("자재구분 코드")
                                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsMaterialPurchaseOrder>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PurchaseOrderId })
                    .HasName("PK_FmsMaterialPurchaseOrder_1");

                entity.Property(e => e.PurchaseOrderId)
                                    .HasComment("자재발주 고유번호")
                                    .ValueGeneratedOnAdd();


                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsMaterialPurchaseOrder)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialOrder__CmSite");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsMaterialPurchaseOrder)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialOrder__CmBusinessField");

                entity.HasOne(d => d.CmFile)
                                    .WithMany(p => p.FmsMaterialPurchaseOrder)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId })
                                    .HasConstraintName("FK__FmsMaterialPurchaseOrder__CmFile");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsMaterialPurchaseOrder)
                                    .HasForeignKey(d => d.OrderUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialOrder__CmUser");

                entity.HasOne(d => d.FmsMaterialPurchaseRequest)
                                    .WithMany(p => p.FmsMaterialPurchaseOrder)
                                    .HasForeignKey(d => new { d.SiteId, d.PurchaseRequestId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialPurchaseOrder_FmsMaterialPurchaseRequest");

                entity.HasOne(d => d.FmsMaterialTradeCompany)
                                    .WithMany(p => p.FmsMaterialPurchaseOrder)
                                    .HasForeignKey(d => new { d.SiteId, d.TradeCompanyId })
                                    .HasConstraintName("FK__FmsMaterialPurchaseOrder__FmsMaterialTradeCompany");
            });

            modelBuilder.Entity<FmsMaterialPurchaseOrderMaterial>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PurchaseOrderId, e.MaterialId })
                    .HasName("PK_FmsMaterialPurchaseOrderMaterial_1");

                entity.HasOne(d => d.FmsMaterial)
                                    .WithMany(p => p.FmsMaterialPurchaseOrderMaterial)
                                    .HasForeignKey(d => new { d.SiteId, d.MaterialId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialPurchaseOrderMaterial_FmsMaterial");

                entity.HasOne(d => d.FmsMaterialPurchaseOrder)
                                    .WithMany(p => p.FmsMaterialPurchaseOrderMaterial)
                                    .HasForeignKey(d => new { d.SiteId, d.PurchaseOrderId })
                                    .HasConstraintName("FK_FmsMaterialPurchaseOrderMaterial_FmsMaterialPurchaseOrder");
            });

            modelBuilder.Entity<FmsMaterialPurchaseRequest>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PurchaseRequestId })
                    .HasName("PK_FmsMaterialPurchaseRequest_1");

                entity.Property(e => e.PurchaseRequestId)
                                    .HasComment("자재발주 요청 고유번호")
                                    .ValueGeneratedOnAdd();


                entity.HasOne(d => d.Progress)
                                    .WithMany(p => p.FmsMaterialPurchaseRequest)
                                    .HasForeignKey(d => d.ProgressId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialPurchasingRequest__FmsMaterialCodeProcess");

                entity.HasOne(d => d.PurchaseType)
                                    .WithMany(p => p.FmsMaterialPurchaseRequest)
                                    .HasForeignKey(d => d.PurchaseTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialPurchaseRequest_FmsMaterialCodePurchaseType");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsMaterialPurchaseRequest)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialPurchasingRequest__CmSite");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsMaterialPurchaseRequestCmUser)
                                    .HasForeignKey(d => d.ApprovalUserId)
                                    .HasConstraintName("FK__FmsMaterialPurchaseRequest__CmUser1_AsApprovalUserId");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsMaterialPurchaseRequest)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialPurchasingRequest__CmBusinessField");

                entity.HasOne(d => d.CmUserNavigation)
                                    .WithMany(p => p.FmsMaterialPurchaseRequestCmUserNavigation)
                                    .HasForeignKey(d => d.RequestUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialPurchaseRequest__CmUser_AsRequestUserId");
            });

            modelBuilder.Entity<FmsMaterialPurchaseRequestMaterial>(entity => {
                entity.HasKey(e => new { e.SiteId, e.PurchaseRequestId, e.MaterialId });

                entity.HasOne(d => d.FmsMaterial)
                    .WithMany(p => p.FmsMaterialPurchaseRequestMaterial)
                    .HasForeignKey(d => new { d.SiteId, d.MaterialId })
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_FmsMaterialPurchaseRequestMaterial_FmsMaterial");

                entity.HasOne(d => d.FmsMaterialPurchaseRequest)
                                    .WithMany(p => p.FmsMaterialPurchaseRequestMaterial)
                                    .HasForeignKey(d => new { d.SiteId, d.PurchaseRequestId })
                                    .HasConstraintName("FK_FmsMaterialPurchaseRequestMaterial_FmsMaterialPurchaseRequest");
            });

            modelBuilder.Entity<FmsMaterialRelease>(entity => {
                entity.HasKey(e => new { e.SiteId, e.MaterialReleaseId });

                entity.Property(e => e.MaterialReleaseId)
                    .HasComment("출고 고유번호")
                    .ValueGeneratedOnAdd();



                entity.HasOne(d => d.AdjustmentType)
                                    .WithMany(p => p.FmsMaterialRelease)
                                    .HasForeignKey(d => d.AdjustmentTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialRelease_FmsMaterialCodeAdjustmentType");

                entity.HasOne(d => d.ReleaseType)
                                    .WithMany(p => p.FmsMaterialRelease)
                                    .HasForeignKey(d => d.ReleaseTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialRelease_FmsMaterialCodeReleaseType");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsMaterialRelease)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialRelease_CmSite");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsMaterialReleaseCmUser)
                                    .HasForeignKey(d => d.AdjustmentUserId)
                                    .HasConstraintName("FK_FmsMaterialRelease_CmUser1");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsMaterialRelease)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialRelease_CmBusinessField");

                entity.HasOne(d => d.CmUserNavigation)
                                    .WithMany(p => p.FmsMaterialReleaseCmUserNavigation)
                                    .HasForeignKey(d => d.ConfirmedUserId)
                                    .HasConstraintName("FK_FmsMaterialRelease_CmUser");

                entity.HasOne(d => d.FmsMaterial)
                                    .WithMany(p => p.FmsMaterialRelease)
                                    .HasForeignKey(d => new { d.SiteId, d.MaterialId })
                                    .HasConstraintName("FK_FmsMaterialRelease_FmsMaterial");

                entity.HasOne(d => d.FmsWorkResult)
                                    .WithMany(p => p.FmsMaterialRelease)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkRequestId })
                                    .HasConstraintName("FK_FmsMaterialRelease_FmsWorkResult");

                entity.HasOne(d => d.FmsWorkResultCheckItemMaterial)
                                    .WithMany(p => p.FmsMaterialRelease)
                                    .HasForeignKey(d => new { d.CheckItemMaterialId })
                                    .HasConstraintName("FK_FmsMaterialRelease_FmsWorkResultCheckItemMaterial");

            });

            modelBuilder.Entity<FmsMaterialStored>(entity => {
                entity.HasKey(e => new { e.SiteId, e.MaterialStoredId })
                    .HasName("PK_FmsMaterialStored_1");

                entity.Property(e => e.MaterialStoredId)
                                    .HasComment("입고 자재 고유번호")
                                    .ValueGeneratedOnAdd();



                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsMaterialStored)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialStored__CmSite");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsMaterialStoredCmUser)
                                    .HasForeignKey(d => d.ApprovalUserId)
                                    .HasConstraintName("FK__FmsMaterialStored__CmUser1_AsApprovalUserId");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsMaterialStored)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialStored__CmBusinessField");

                entity.HasOne(d => d.FmsMaterial)
                                    .WithMany(p => p.FmsMaterialStored)
                                    .HasForeignKey(d => new { d.SiteId, d.MaterialId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialStored_FmsMaterial");

                entity.HasOne(d => d.FmsMaterialPurchaseOrder)
                                    .WithMany(p => p.FmsMaterialStored)
                                    .HasForeignKey(d => new { d.SiteId, d.PurchaseOrderId })
                                    .HasConstraintName("FK_FmsMaterialStored_FmsMaterialPurchaseOrder");

                entity.HasOne(d => d.S)
                                    .WithMany(p => p.FmsMaterialStoredS)
                                    .HasForeignKey(d => d.StoredUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialStored__CmUser_AsStoredUserId");

                entity.HasOne(d => d.FmsMaterialWarehouse)
                                    .WithMany(p => p.FmsMaterialStored)
                                    .HasForeignKey(d => new { d.SiteId, d.WarehouseId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsMaterialStored_FmsMaterialWarehouse");
            });

            modelBuilder.Entity<FmsMaterialTradeCompany>(entity => {
                entity.HasKey(e => new { e.SiteId, e.TradeCompanyId })
                    .HasName("PK__FmsMater__E1CDA95A8D3DA6AC");

                entity.Property(e => e.TradeCompanyId)
                                    .HasComment("자재구매 회사 고유번호")
                                    .ValueGeneratedOnAdd();

                entity.Property(e => e.AddressZip1)
                                    .IsFixedLength()
                                    .HasComment("회사 우편번호 1");

                entity.Property(e => e.AddressZip2)
                                    .IsFixedLength()
                                    .HasComment("회사 우편번호 2");


                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsMaterialTradeCompany)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialTradeCompany__CmSite");
            });

            modelBuilder.Entity<FmsMaterialWarehouse>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WarehouseId })
                    .HasName("PK_FmsMaterialWarehouse_1");

                entity.Property(e => e.WarehouseId)
                                    .HasComment("자재창고 고유번호")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsMaterialWarehouse)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialWarehouse__CmSite");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsMaterialWarehouse)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsMaterialWarehouse__CmBusinessField");
            });


            modelBuilder.Entity<FmsMonthlyStoredReleaseStatusView>(entity => {
                entity.HasNoKey();

                entity.ToView("FmsMonthlyStoredReleaseStatusView");
            });

            modelBuilder.Entity<FmsPaymentType>(entity => {
                entity.HasKey(e => new { e.PaymentTypeId });

                entity.Property(e => e.PaymentTypeId)
                    .HasComment("지급구분 코드")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<FmsReport>(entity => {
                entity.HasKey(e => new { e.SiteId, e.Rid });

                entity.Property(e => e.Rid)
                    .HasComment("레포트 고유번호")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsReport)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsReport_CmSite");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsReport)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsReport_CmBusinessField");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsReportCmUser)
                                    .HasForeignKey(d => d.ConfirmUserId1)
                                    .HasConstraintName("FK_FmsReport_CmUser1");

                entity.HasOne(d => d.CmUserNavigation)
                                    .WithMany(p => p.FmsReportCmUserNavigation)
                                    .HasForeignKey(d => d.ConfirmUserId2)
                                    .HasConstraintName("FK_FmsReport_CmUser2");

                entity.HasOne(d => d.CmFile)
                                    .WithMany(p => p.FmsReport)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId })
                                    .HasConstraintName("FK_FmsReport_CmFile");

                entity.HasOne(d => d.CmUser1)
                                    .WithMany(p => p.FmsReportCmUser1)
                                    .HasForeignKey(d => d.RegisterUserId)
                                    .HasConstraintName("FK_FmsReport_CmUser");
            });

            modelBuilder.Entity<FmsShortStockStatusView>(entity => {
                entity.HasNoKey();

                entity.ToView("FmsShortStockStatusView");
            });

            modelBuilder.Entity<FmsWorkCodeCauseClass>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CauseClassId })
                    .HasName("PK__FmsWorkC__41B36FA8A0A50888");

                entity.Property(e => e.CauseClassId)
                                    .HasComment("원인 종류 코드")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsWorkCodeCauseClass)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkCodeCauseClass__CmSite");
            });

            modelBuilder.Entity<FmsWorkCodeCycleUnit>(entity => {
                entity.HasKey(e => new { e.SiteId, e.CycleUnitId })
                    .HasName("PK__FmsFacil__FD93E7A8F9008927");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsWorkCodeCycleUnit)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkCodeCycleUnit__CmSite");
            });

            modelBuilder.Entity<FmsWorkCodeEmergency>(entity => {
                entity.HasKey(e => new { e.SiteId, e.EmergencyId })
                    .HasName("PK__FmsWorkC__9E69ED2E2DF97B9E");

                entity.Property(e => e.EmergencyId)
                                    .HasComment("긴급 작업 고유번호")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsWorkCodeEmergency)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkCodeEmergency__CmSite");
            });

            modelBuilder.Entity<FmsWorkCodeHolidayWorkType>(entity => {
                entity.HasKey(e => new { e.SiteId, e.HolidayWorkTypeId })
                    .HasName("PK__FmsWorkC__AADC648E16ABB84E");

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsWorkCodeHolidayWorkType)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkCodeHolidayWorkType__CmSite");
            });

            modelBuilder.Entity<FmsWorkCodeLegalInspectionAgency>(entity => {
                entity.HasKey(e => new { e.SiteId, e.InspectionAgencyId })
                    .HasName("PK__FmsWorkC__C77D9EF75644DF2B");

                entity.Property(e => e.InspectionAgencyId).ValueGeneratedOnAdd();

                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsWorkCodeLegalInspectionAgency)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkCodeLegalInspectionAgency__CmSite");
            });

            modelBuilder.Entity<FmsWorkCodeProgress>(entity => {
                entity.HasKey(e => e.WorkProgressId)
                    .HasName("PK__FmsWorkC__1ECF32EBC781395E");

                entity.Property(e => e.WorkProgressId)
                                    .HasComment("작업 진행상태 고유번호")
                                    .ValueGeneratedNever();

            });

            modelBuilder.Entity<FmsWorkCodeType>(entity => {
                entity.HasKey(e => e.WorkTypeId)
                    .HasName("PK__FmsWorkC__CCC06D20DC518AA2");

            });

            modelBuilder.Entity<FmsWorkOrder>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId });


                entity.HasOne(d => d.Site)
                    .WithMany(p => p.FmsWorkOrder)
                    .HasForeignKey(d => d.SiteId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__FmsWorkOrder__CmSite");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsWorkOrder)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkOrder__CmBusinessField");

                entity.HasOne(d => d.FmsWorkCodeEmergency)
                                    .WithMany(p => p.FmsWorkOrder)
                                    .HasForeignKey(d => new { d.SiteId, d.EmergencyId })
                                    .HasConstraintName("FK__FmsWorkOrder__FmsWorkCodeEmergency");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsWorkOrder)
                                    .HasForeignKey(d => d.OrderUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkOrder__CmUser");

                entity.HasOne(d => d.FmsWorkRequest)
                                    .WithOne(p => p.FmsWorkOrder)
                                    .HasForeignKey<FmsWorkOrder>(d => new { d.SiteId, d.WorkRequestId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkOrder__FmsWorkRequest");
            });

            modelBuilder.Entity<FmsWorkOrderToFacility>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId, e.FacilityCode })
                    .HasName("PK__FmsWorkO__85930B3FA02FC407");

                entity.HasOne(d => d.CmFacility)
                                    .WithMany(p => p.FmsWorkOrderToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsWorkOrderToFacility_CmFacility");

                entity.HasOne(d => d.FmsWorkOrder)
                                    .WithMany(p => p.FmsWorkOrderToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkRequestId })
                                    .HasConstraintName("FK__FmsWorkOrderToFacility__FmsWorkOrder");
            });

            modelBuilder.Entity<FmsWorkRequest>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId })
                    .HasName("PK__FmsWorkR__14C63A9A32B3A813");

                entity.Property(e => e.WorkRequestId)
                                    .HasComment("작업요청 고유번호")
                                    .ValueGeneratedOnAdd();


                entity.HasOne(d => d.Site)
                                    .WithMany(p => p.FmsWorkRequest)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkRequest__CmSite");

                entity.HasOne(d => d.WorkProgress)
                                    .WithMany(p => p.FmsWorkRequest)
                                    .HasForeignKey(d => d.WorkProgressId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkRequest__FmsWorkCodeProgress");

                entity.HasOne(d => d.WorkType)
                                    .WithMany(p => p.FmsWorkRequest)
                                    .HasForeignKey(d => d.WorkTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkRequest__FmsWorkCodeWorkType");

                entity.HasOne(d => d.WorkDetailType)
                                    .WithMany()
                                    .HasForeignKey(d => d.WorkDetailTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsWorkRequest_FmsWorkCodeDetailType");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsWorkRequest)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkRequest__CmBusinessField");

                entity.HasOne(d => d.WorkPartner)
                                    .WithMany()
                                    .HasForeignKey(d => new { d.SiteId, d.WorkPartnerId })
                                    .HasConstraintName("FK_FmsWorkRequest_CmPartner_WorkPartner");

                entity.HasOne(d => d.CmPartner)
                                    .WithMany(p => p.FmsWorkRequest)
                                    .HasForeignKey(d => new { d.SiteId, d.InspectionAgencyId })
                                    .HasConstraintName("FK_FmsWorkRequest_CmPartner");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsWorkRequestCmUser)
                                    .HasForeignKey(d => d.RejectUserId)
                                    .HasConstraintName("FK__FmsWorkRequest__CmUser1_AsRejectUserId");

                entity.HasOne(d => d.CmUserNavigation)
                                    .WithMany(p => p.FmsWorkRequestCmUserNavigation)
                                    .HasForeignKey(d => d.RequestUserId)
                                    .HasConstraintName("FK__FmsWorkRequest__CmUser_AsRequestUserId");

                entity.HasOne(d => d.FmsWorkSchedule)
                                    .WithMany(p => p.FmsWorkRequest)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkScheduleId })
                                    .HasConstraintName("FK__FmsWorkRequest__FmsWorkSchedule");


                entity.HasOne(d => d.CmFile)
                .WithMany(p => p.FmsWorkRequest)
                .HasForeignKey(d => new { d.SiteId, d.FileId })
                .HasConstraintName("FK_FmsWorkRequest_CmFile");
            });

            modelBuilder.Entity<FmsWorkRequestToFacility>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId, e.FacilityCode })
                    .HasName("PK__FmsWorkR__626EDDD7021403C4");

                entity.HasOne(d => d.CmFacility)
                                    .WithMany(p => p.FmsWorkRequestToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsWorkRequestToFacility_CmFacility");

                entity.HasOne(d => d.FmsWorkRequest)
                                    .WithMany(p => p.FmsWorkRequestToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkRequestId })
                                    .HasConstraintName("FK__FmsWorkRequestToFacility__FmsWorkRequest");
            });

            modelBuilder.Entity<FmsWorkResult>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId });


                entity.HasOne(d => d.FmsWorkCodeCauseClass)
                    .WithMany(p => p.FmsWorkResult)
                    .HasForeignKey(d => new { d.SiteId, d.CauseClassId })
                    .HasConstraintName("FK__FmsWorkResult__FmsWorkCodeCauseClass");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsWorkResultCmUser)
                                    .HasForeignKey(d => d.ConfirmedUserId)
                                    .HasConstraintName("FK__FmsWorkResult__CmUser1_AsConfirmedUserId");

                entity.HasOne(d => d.FmsWorkOrder)
                                    .WithOne(p => p.FmsWorkResult)
                                    .HasForeignKey<FmsWorkResult>(d => new { d.SiteId, d.WorkRequestId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkResult__FmsWorkOrder");

                entity.HasOne(d => d.FmsWorkRequest)
                                    .WithOne(p => p.FmsWorkResult)
                                    .HasForeignKey<FmsWorkResult>(d => new { d.SiteId, d.WorkRequestId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkResult__FmsWorkRequest");

                entity.HasOne(d => d.CmUserNavigation)
                                    .WithMany(p => p.FmsWorkResultCmUserNavigation)
                                    .HasForeignKey(d => d.WorkerUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkResult__CmUser_AsWorkerUserId");
            });

            modelBuilder.Entity<FmsWorkResultCheckItem>(entity => {
                entity.HasKey(e => e.CheckItemId)
                    .HasName("PK_FmsWorkResultCheckItem_1");

                entity.Property(e => e.CheckItemId)
                                    .HasComment("작업이력 고유번호")
                                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.CmFacility)
                                    .WithMany(p => p.FmsWorkResultCheckItem)
                                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                                    .HasConstraintName("FK__FmsWorkResultCheckItem__CmFacility");

                entity.HasOne(d => d.FmsWorkResult)
                                    .WithMany(p => p.FmsWorkResultCheckItem)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkRequestId })
                                    .HasConstraintName("FK__FmsWorkResultCheckItem__FmsWorkResult");

                entity.HasOne(d => d.FmsFacilityCheckItem)
                                    .WithMany(p => p.FmsWorkResultCheckItem)
                                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode, d.CheckItemId })
                                    .HasConstraintName("FK__FmsWorkResultCheckItem__FmsFacilityCheckItem");
            });

            modelBuilder.Entity<FmsWorkResultCheckItemMaterial>(entity => {
                entity.HasKey(e => e.CheckItemMaterialId)
                    .HasName("PK_FmsWorkResultCheckItemMaterial_1");

                entity.HasOne(d => d.CheckItem)
                                    .WithMany(p => p.FmsWorkResultCheckItemMaterial)
                                    .HasForeignKey(d => d.CheckItemId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsWorkResultCheckItemMaterial_FmsWorkResultCheckItem");

                entity.HasOne(d => d.FmsMaterial)
                                    .WithMany(p => p.FmsWorkResultCheckItemMaterial)
                                    .HasForeignKey(d => new { d.SiteId, d.MaterialId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsWorkResultCheckItemMaterial_FmsMaterial");

                entity.HasOne(d => d.FmsWorkResult)
                                    .WithMany(p => p.FmsWorkResultCheckItemMaterial)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkRequestId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsWorkResultCheckItemMaterial_FmsWorkResult");
            });

            modelBuilder.Entity<FmsWorkResultFile>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId })
                    .HasName("PK__FmsWorkR__F33BEC723A2A01CC");

                entity.HasOne(d => d.CmFile)
                                    .WithMany(p => p.FmsWorkResultFile)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkResultFile__CmFile");

                entity.HasOne(d => d.FmsWorkResult)
                                    .WithOne(p => p.FmsWorkResultFile)
                                    .HasForeignKey<FmsWorkResultFile>(d => new { d.SiteId, d.WorkRequestId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkResultFile__FmsWorkResult");
            });

            modelBuilder.Entity<FmsWorkResultLaw>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId })
                    .HasName("PK__FmsWorkR__F33BEC72E18C69BB");

                entity.HasOne(d => d.FmsWorkResult)
                                    .WithOne(p => p.FmsWorkResultLaw)
                                    .HasForeignKey<FmsWorkResultLaw>(d => new { d.SiteId, d.WorkRequestId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkResultLaw__FmsWorkResult");
            });

            modelBuilder.Entity<FmsWorkResultToFacility>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId, e.FacilityCode })
                    .HasName("PK__FmsWorkR__85930B3F1D5F5DA3");

                entity.HasOne(d => d.CmFacility)
                                    .WithMany(p => p.FmsWorkResultToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkResultToFacility__CmFacility");

                entity.HasOne(d => d.FmsWorkResult)
                                    .WithMany(p => p.FmsWorkResultToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkRequestId })
                                    .HasConstraintName("FK__FmsWorkResultToFacility__FmsWorkOrder");
            });

            modelBuilder.Entity<FmsWorkSchedule>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkScheduleId })
                    .HasName("PK__FmsWorkS__45B67F5033D5F129");

                entity.Property(e => e.WorkScheduleId)
                                    .HasComment("작업일정 고유번호")
                                    .ValueGeneratedOnAdd();


                entity.HasOne(d => d.WorkType)
                                    .WithMany(p => p.FmsWorkSchedule)
                                    .HasForeignKey(d => d.WorkTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkSchedule__FmsWorkCodeWorkType");

                entity.HasOne(d => d.CmBusinessField)
                                    .WithMany(p => p.FmsWorkSchedule)
                                    .HasForeignKey(d => new { d.BusinessFieldId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkSchedule__CmBusinessField");

                entity.HasOne(d => d.FmsWorkCodeCycleUnit)
                                    .WithMany(p => p.FmsWorkSchedule)
                                    .HasForeignKey(d => new { d.SiteId, d.CycleUnitId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkSchedule__FmsWorkCodeCycleUnit");

                entity.HasOne(d => d.FmsWorkCodeHolidayWorkType)
                                    .WithMany(p => p.FmsWorkSchedule)
                                    .HasForeignKey(d => new { d.SiteId, d.HolidayWorkTypeId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkSchedule__FmsWorkCodeHolidayWorkType");

                entity.HasOne(d => d.CmPartner)
                                    .WithMany(p => p.FmsWorkSchedule)
                                    .HasForeignKey(d => new { d.SiteId, d.InspectionAgencyId })
                                    .HasConstraintName("FK_FmsWorkSchedule_CmPartner");

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.FmsWorkSchedule)
                                    .HasForeignKey(d => d.UpdateUserId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkSchedule__CmUser");

                entity.HasOne(d => d.CmFile)
                                    .WithMany(p => p.FmsWorkSchedule)
                                    .HasForeignKey(d => new { d.SiteId, d.FileId })
                                    .HasConstraintName("FK_FmsWorkSchedule_CmFile");

            });

            modelBuilder.Entity<FmsWorkScheduleToFacility>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkScheduleId, e.FacilityCode })
                    .HasName("PK__FmsWorkS__331E981DC77EA20D");

                entity.HasOne(d => d.CmFacility)
                                    .WithMany(p => p.FmsWorkScheduleToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.FacilityCode })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsWorkScheduleToFacility_CmFacility");

                entity.HasOne(d => d.FmsWorkSchedule)
                                    .WithMany(p => p.FmsWorkScheduleToFacility)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkScheduleId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK__FmsWorkScheduleToFacility__FmsWorkSchedule");
            });


            modelBuilder.Entity<WeatherDongNaeForecast>(entity => {
                entity.HasKey(e => new { e.BaseTime, e.ForecastTime });
            });

            modelBuilder.Entity<WeatherDustSidoInfo>(entity => {
                entity.HasNoKey();
            });

            modelBuilder.Entity<WeatherShortTermForecast>(entity => {
                entity.HasNoKey();
            });

            modelBuilder.Entity<WeatherShortTermNowValue>(entity => {
                entity.HasNoKey();
            });

            modelBuilder.Entity<SitemapAuth>(entity => {
                entity.Property(e => e.SitemapAuthId)
                    .HasDefaultValueSql("newid()");
            });

            modelBuilder.Entity<CmTenant>(entity => {
                entity.HasKey(e => new { e.SiteId, e.TenantId });

                entity.Property(e => e.TenantId)
                    .HasComment("입점업체 고유 번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsWorkCodeDetailType>(entity => {
                entity.HasKey(e => e.WorkDetailTypeId)
                    .HasName("PK_FmsWorkCodeDetailType");

                entity.HasOne(d => d.FmsWorkCodeType)
                                    .WithMany()
                                    .HasForeignKey(d => new { d.WorkTypeId })
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsWorkCodeDetailType_FmsWorkCodeType");

            });

            modelBuilder.Entity<FmsWorkRequestToAccident>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId, e.AccidentId })
                    .HasName("PK_FmsWorkRequestToAccident");

                entity.HasOne(d => d.FmsAccident)
                                    .WithMany(p => p.FmsWorkRequestToAccident)
                                    .HasForeignKey(d => new { d.SiteId, d.AccidentId })
                                    .OnDelete(DeleteBehavior.Cascade)
                                    .HasConstraintName("FK_FmsWorkRequestToAccident_FmsAccident");

                entity.HasOne(d => d.FmsWorkRequest)
                                    .WithMany(p => p.FmsWorkRequestToAccident)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkRequestId })
                                    .HasConstraintName("FK_FmsWorkRequestToAccident_FmsWorkRequest");
            });

            modelBuilder.Entity<FmsWorkRequestToComplaint>(entity => {
                entity.HasKey(e => new { e.SiteId, e.WorkRequestId, e.ComplaintId })
                    .HasName("PK_FmsWorkRequestToComplaint");

                entity.HasOne(d => d.FmsComplaints)
                                    .WithMany(p => p.FmsWorkRequestToComplaint)
                                    .HasForeignKey(d => new { d.SiteId, d.ComplaintId })
                                    .OnDelete(DeleteBehavior.Cascade)
                                    .HasConstraintName("FK_FmsWorkRequestToComplaint_FmsComplaints");

                entity.HasOne(d => d.FmsWorkRequest)
                                    .WithMany(p => p.FmsWorkRequestToComplaint)
                                    .HasForeignKey(d => new { d.SiteId, d.WorkRequestId })
                                    .HasConstraintName("FK_FmsWorkRequestToComplaint_FmsWorkRequest");
            });

            modelBuilder.Entity<FmsMaterialReleaseDetail>(entity => {
                entity.HasKey(e => new { e.MaterialReleaseDetailId });

                entity.Property(e => e.MaterialReleaseDetailId)
                    .HasComment("출고상세 고유번호")
                    .ValueGeneratedOnAdd();


                entity.HasOne(d => d.FmsMaterialRelease)
                                    .WithMany(p => p.FmsMaterialReleaseDetail)
                                    .HasForeignKey(d => new { d.SiteId, d.MaterialReleaseId })
                                    .HasConstraintName("FK_FmsMaterialReleaseDetail_FmsMaterialRelease");

                entity.HasOne(d => d.FmsMaterialStored)
                                    .WithMany(p => p.FmsMaterialReleaseDetail)
                                    .HasForeignKey(d => new { d.SiteId, d.MaterialStoredId })
                                    .HasConstraintName("FK_FmsMaterialReleaseDetail_FmsMaterialStored");
            });
            modelBuilder.Entity<FmsAlarmPoint>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId });
            });
            modelBuilder.Entity<FmsAlarmLog>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FacilityCode, e.PropertyId, e.CreatedDateTime });
            });
            modelBuilder.Entity<MobileShortcut>(entity => {
                entity.Property(e => e.MobileShortcutId)
                    .HasComment("모바일 단축메뉴 고유번호")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.CmUser)
                                    .WithMany(p => p.MobileShortcuts)
                                    .HasForeignKey(d => d.UserId)
                                    .OnDelete(DeleteBehavior.Cascade)
                                    .HasConstraintName("FK_MobileShortcut_CmUser");

                entity.HasOne(d => d.Sitemap)
                                    .WithMany(p => p.MobileShortcuts)
                                    .HasForeignKey(d => d.SitemapId)
                                    .OnDelete(DeleteBehavior.Cascade)
                                    .HasConstraintName("FK_MobileShortcut_Sitemap");
            });


            modelBuilder.Entity<CmInvestigation1CodeGroup>(entity => {
                entity.HasKey(e => new { e.InvestigationGroupId });

                entity.Property(e => e.InvestigationGroupId)
                    .HasComment("정보조사 그룹 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmInvestigation1CodeType>(entity => {
                entity.HasKey(e => new { e.InvestigationTypeId });

                entity.Property(e => e.InvestigationTypeId)
                    .HasComment("정보조사 유형 고유번호")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<CmInvestigation2CodeGroup>(entity => {
                entity.HasKey(e => new { e.InvestigationGroupId });

                entity.Property(e => e.InvestigationGroupId)
                    .HasComment("정보조사 그룹 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmInvestigation2CodeType>(entity => {
                entity.HasKey(e => new { e.InvestigationTypeId });

                entity.Property(e => e.InvestigationTypeId)
                    .HasComment("정보조사 유형 고유번호")
                    .ValueGeneratedOnAdd();

            });
            modelBuilder.Entity<CmInvestigation3CodeGroup>(entity => {
                entity.HasKey(e => new { e.InvestigationGroupId });

                entity.Property(e => e.InvestigationGroupId)
                    .HasComment("정보조사 그룹 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmInvestigation3CodeType>(entity => {
                entity.HasKey(e => new { e.InvestigationTypeId });

                entity.Property(e => e.InvestigationTypeId)
                    .HasComment("정보조사 유형 고유번호")
                    .ValueGeneratedOnAdd();

            });

            modelBuilder.Entity<CmInvestigation1>(entity => {
                entity.HasKey(e => new { e.SiteId, e.InvestigationId });

                entity.Property(e => e.InvestigationId)
                    .HasComment("정보조사 고유 번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmInvestigation1History>(entity => {
                entity.HasKey(e => new { e.SiteId, e.InvestigationId, e.HistoryId });

                entity.Property(e => e.HistoryId)
                    .HasComment("설비 정보조사 수정 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmInvestigation2>(entity => {
                entity.HasKey(e => new { e.SiteId, e.InvestigationId });

                entity.Property(e => e.InvestigationId)
                    .HasComment("정보조사 고유 번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmInvestigation2History>(entity => {
                entity.HasKey(e => new { e.SiteId, e.InvestigationId, e.HistoryId });

                entity.Property(e => e.HistoryId)
                    .HasComment("설비 정보조사 수정 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmInvestigation3>(entity => {
                entity.HasKey(e => new { e.SiteId, e.InvestigationId });

                entity.Property(e => e.InvestigationId)
                    .HasComment("정보조사 고유 번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<CmInvestigation3History>(entity => {
                entity.HasKey(e => new { e.SiteId, e.InvestigationId, e.HistoryId });

                entity.Property(e => e.HistoryId)
                    .HasComment("설비 정보조사 수정 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsFacilityState>(entity => {
                entity.HasKey(e => new { e.FacilityStateId });

                entity.Property(e => e.FacilityStateId)
                    .HasComment("주요 설비 현황 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsFacilityStateDetail>(entity => {
                entity.HasKey(e => new { e.FacilityStateDetailId });

                entity.Property(e => e.FacilityStateDetailId)
                    .HasComment("주요 설비 현황 상세 고유번호")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.CmSite)
                                    .WithMany(p => p.FmsFacilityStateDetail)
                                    .HasForeignKey(d => d.SiteId)
                                    .HasConstraintName("FK__FmsFacilityStateDetail__CmSite");

                entity.HasOne(d => d.FmsFacilityState)
                                    .WithMany(p => p.FmsFacilityStateDetail)
                                    .HasForeignKey(d => d.FacilityStateId)
                                    .HasConstraintName("FK_FmsFacilityStateDetail_FmsFacilityState");
            });


            modelBuilder.Entity<CmSurvey>(entity => {
                entity.HasKey(e => new { e.SurveyId });

                entity.Property(e => e.SurveyId)
                    .HasComment("설문지 고유번호")
                    .ValueGeneratedOnAdd();
            });

            modelBuilder.Entity<FmsEnergyAnalysis>(entity => {
                entity.HasKey(e => new { e.SiteId, e.FuelTypeId, e.FuelPriceId, e.PriceTypeId, e.Year, e.Month })
                    .HasName("PK_FmsEnergyAnalysis");

                entity.HasOne(d => d.CmSite)
                                    .WithMany(p => p.FmsEnergyAnalysis)
                                    .HasForeignKey(d => d.SiteId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsEnergyAnalysis__CmSite");

                entity.HasOne(d => d.FuelType)
                                    .WithMany(p => p.FmsEnergyAnalysis)
                                    .HasForeignKey(d => d.FuelTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsEnergyAnalysis__BemsFuelType");

                entity.HasOne(d => d.PriceType)
                                    .WithMany(p => p.FmsEnergyAnalysis)
                                    .HasForeignKey(d => d.PriceTypeId)
                                    .OnDelete(DeleteBehavior.ClientSetNull)
                                    .HasConstraintName("FK_FmsEnergyAnalysis__BemsPriceType");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
