Ich versuche, Saatdaten zu erstellen. Wenn ich "Dotnet EF -Datenbank -Update" ausführe, erhalte ich den folgenden Fehler: < /p>
Build started...
Build succeeded.
System.InvalidOperationException: An error was generated for warning
'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning':
The model for context 'RepositoryContext' has pending changes. Add a
new migration before updating the database. This exception can be
suppressed or logged by passing event ID
'RelationalEventId.PendingModelChangesWarning' to the
'ConfigureWarnings' method in 'DbContext.OnConfiguring' or
'AddDbContext'.
at Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition`1.Log[TLoggerCategory](IDiagnosticsLogger`1 logger, TParam arg)
at Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggerExtensions.PendingModelChangesWarning(IDiagnosticsLogger`1 diagnostics, Type contextType)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.c__DisplayClass0_0.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
< /code>
Es wurde ein Fehler für die Warnung generiert. Fügen Sie eine neue Migration hinzu, bevor Sie die Datenbank aktualisieren. Diese Ausnahme kann
unterdrückt oder protokolliert werden, indem Ereignis -ID
'relationalEvent.PendingModelChangesWarning 'an die Methode
' configureWarnings 'in' dbcontext.onconfiguring 'oder
'addbcontext. & $ -Ccontext.Br /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /blockt, eingelegt werden. : < /p>
using Entities.Models;
using Entities.Models.Enums;
using Microsoft.EntityFrameworkCore;
namespace Repositories
{
public class RepositoryContext : DbContext
{
public DbSet AgeGroups { get; set; }
public DbSet Hairdressers { get; set; }
public DbSet HairdressingServices { get; set; }
public DbSet CustomerAppointments { get; set; }
public DbSet HairdressingServiceLocalizations { get; set; }
public RepositoryContext(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity().HasMany(x => x.AgeGroups)
.WithMany(y => y.HairdressingService)
.UsingEntity("HairdressingServiceAgeGroups");
modelBuilder.Entity().HasOne(l => l.HairdressingService)
.WithMany(h => h.Localizations)
.HasForeignKey(l => l.HairdressingServiceId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity().HasMany(x => x.HairdressingServices)
.WithMany(y => y.Hairdresser)
.UsingEntity("HairdresserHairdressingServices");
modelBuilder.Entity().HasMany(c => c.HairdressingServices)
.WithMany(h => h.CustomerAppointment)
.UsingEntity("CustomerAppointmentHairdressingServices");
SeedingData(modelBuilder);
}
private void SeedingData(ModelBuilder modelBuilder)
{
var ageGroup1 = new AgeGroup { Id = 1, MinAge = 0, MaxAge = 17 };
var ageGroup2 = new AgeGroup { Id = 2, MinAge = 18, MaxAge = 75 };
var ageGroup3 = new AgeGroup { Id = 3, MinAge = 76, MaxAge = 125 };
var ageGroup = new List();
ageGroup.Add(ageGroup1);
ageGroup.Add(ageGroup2);
var hairdressingService1 = new HairdressingService { Id = 1, Name = "HairCut", Genders = { Gender.m }, Duration = new TimeSpan(0, 20, 0), Price = 100, Status = true };
var hairdressingService2 = new HairdressingService { Id = 2, Name = "RazorShave", Genders = { Gender.m }, Duration = new TimeSpan(0, 40, 0), Price = 200, Status = true };
var hairdressingService3 = new HairdressingService { Id = 3, Name = "HairColoring", Genders = { Gender.m }, Duration = new TimeSpan(0, 60, 0), Price = 300, Status = true };
var hairdressingService4 = new HairdressingService { Id = 4, Name = "BrowShaping", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 80, 0), Price = 400, Status = true };
var hairdressingService5 = new HairdressingService { Id = 5, Name = "BeardGrooming", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 100, 0), Price = 500, Status = true };
var hairdressingService6 = new HairdressingService { Id = 6, Name = "ChildShave", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 120, 0), Price = 600, Status = true };
var hairdressingService7 = new HairdressingService { Id = 7, Name = "PermHair", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 140, 0), Price = 700, Status = false };
var hairdressingService8 = new HairdressingService { Id = 8, Name = "Manicure", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 150, 0), Price = 800, Status = false };
var hairdressingService9 = new HairdressingService { Id = 9, Name = "Pedicure", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 160, 0), Price = 900, Status = false };
var hairdressingService10 = new HairdressingService { Id = 10, Name = "GroomsCut", Genders = { Gender.m }, Duration = new TimeSpan(0, 180, 0), Price = 1000, Status = true };
var hairdressingService11 = new HairdressingService { Id = 11, Name = "Makeup(Bride)", Genders = { Gender.f }, Duration = new TimeSpan(0, 200, 0), Price = 1100, Status = false };
List hairdressingServices = new List();
hairdressingServices.Add(hairdressingService1);
hairdressingServices.Add(hairdressingService2);
hairdressingServices.Add(hairdressingService3);
hairdressingServices.Add(hairdressingService4);
hairdressingServices.Add(hairdressingService5);
hairdressingServices.Add(hairdressingService6);
hairdressingServices.Add(hairdressingService7);
hairdressingServices.Add(hairdressingService8);
hairdressingServices.Add(hairdressingService9);
hairdressingServices.Add(hairdressingService10);
hairdressingServices.Add(hairdressingService11);
var hairdresser1 = new Hairdresser { Id = 1, IdentityUserId = "1", Name = "Aydın", Surname = "Sevim", CanTakeClients = true };
var hairdresser2 = new Hairdresser { Id = 2, IdentityUserId = "2", Name = "Alpay", Surname = "Aydıngüler", CanTakeClients = true };
var hairdresser3 = new Hairdresser { Id = 3, IdentityUserId = "2", Name = "Deniz", Surname = "Dağ", CanTakeClients = false };
var hairdressers = new List();
hairdressers.Add(hairdresser1);
hairdressers.Add(hairdresser2);
hairdressers.Add(hairdresser3);
modelBuilder.Entity().HasData(ageGroup1, ageGroup2, ageGroup3);
modelBuilder.Entity().HasData(hairdressingServices);
modelBuilder.Entity().HasData(hairdressers);
modelBuilder.Entity("HairdressingServiceAgeGroups").HasData(
new { HairdressingServiceId = 1, AgeGroupsId = 1 },
new { HairdressingServiceId = 2, AgeGroupsId = 2 },
new { HairdressingServiceId = 3, AgeGroupsId = 1 },
new { HairdressingServiceId = 3, AgeGroupsId = 2 },
new { HairdressingServiceId = 4, AgeGroupsId = 1 },
new { HairdressingServiceId = 5, AgeGroupsId = 1 },
new { HairdressingServiceId = 5, AgeGroupsId = 2 },
new { HairdressingServiceId = 6, AgeGroupsId = 1 },
new { HairdressingServiceId = 7, AgeGroupsId = 2 },
new { HairdressingServiceId = 8, AgeGroupsId = 2 },
new { HairdressingServiceId = 9, AgeGroupsId = 2 },
new { HairdressingServiceId = 10, AgeGroupsId = 2 },
new { HairdressingServiceId = 11, AgeGroupsId = 2 }
);
modelBuilder.Entity().HasData(// HairCut
new HairdressingServiceLocalization { Id = 1, HairdressingServiceId = 1, Language = "en-GB", Name = "Hair Cut" },
new HairdressingServiceLocalization { Id = 2, HairdressingServiceId = 1, Language = "tr-TR", Name = "Saç Kesimi" },
// RazorShave
new HairdressingServiceLocalization { Id = 3, HairdressingServiceId = 2, Language = "en-GB", Name = "Razor Shave" },
new HairdressingServiceLocalization { Id = 4, HairdressingServiceId = 2, Language = "tr-TR", Name = "Jilet Traşı" },
// HairColoring
new HairdressingServiceLocalization { Id = 5, HairdressingServiceId = 3, Language = "en-GB", Name = "Hair Coloring" },
new HairdressingServiceLocalization { Id = 6, HairdressingServiceId = 3, Language = "tr-TR", Name = "Saç Boyama" },
// BrowShaping
new HairdressingServiceLocalization { Id = 7, HairdressingServiceId = 4, Language = "en-GB", Name = "Brow Shaping" },
new HairdressingServiceLocalization { Id = 8, HairdressingServiceId = 4, Language = "tr-TR", Name = "Kaş Şekillendirme" },
// BeardGrooming
new HairdressingServiceLocalization { Id = 9, HairdressingServiceId = 5, Language = "en-GB", Name = "Beard Grooming" },
new HairdressingServiceLocalization { Id = 10, HairdressingServiceId = 5, Language = "tr-TR", Name = "Sakal Bakımı" },
// ChildShave
new HairdressingServiceLocalization { Id = 11, HairdressingServiceId = 6, Language = "en-GB", Name = "Child Shave" },
new HairdressingServiceLocalization { Id = 12, HairdressingServiceId = 6, Language = "tr-TR", Name = "Çocuk Tıraşı" },
// PermHair
new HairdressingServiceLocalization { Id = 13, HairdressingServiceId = 7, Language = "en-GB", Name = "Perm Hair" },
new HairdressingServiceLocalization { Id = 14, HairdressingServiceId = 7, Language = "tr-TR", Name = "Perma Saç" },
// Manicure
new HairdressingServiceLocalization { Id = 15, HairdressingServiceId = 8, Language = "en-GB", Name = "Manicure" },
new HairdressingServiceLocalization { Id = 16, HairdressingServiceId = 8, Language = "tr-TR", Name = "Manikür" },
// Pedicure
new HairdressingServiceLocalization { Id = 17, HairdressingServiceId = 9, Language = "en-GB", Name = "Pedicure" },
new HairdressingServiceLocalization { Id = 18, HairdressingServiceId = 9, Language = "tr-TR", Name = "Pedikür" },
// GroomsCut
new HairdressingServiceLocalization { Id = 19, HairdressingServiceId = 10, Language = "en-GB", Name = "Groom's Cut" },
new HairdressingServiceLocalization { Id = 20, HairdressingServiceId = 10, Language = "tr-TR", Name = "Damat Kesimi" },
// Makeup(Bride)
new HairdressingServiceLocalization { Id = 21, HairdressingServiceId = 11, Language = "en-GB", Name = "Makeup (Bride)" },
new HairdressingServiceLocalization { Id = 22, HairdressingServiceId = 11, Language = "tr-TR", Name = "Makyaj (Gelin)" });
modelBuilder.Entity("HairdresserHairdressingServices").HasData(
new { HairdresserId = 1, HairdressingServicesId = 1 },
new { HairdresserId = 1, HairdressingServicesId = 2 },
new { HairdresserId = 1, HairdressingServicesId = 3 },
new { HairdresserId = 1, HairdressingServicesId = 4 },
new { HairdresserId = 1, HairdressingServicesId = 5 },
new { HairdresserId = 2, HairdressingServicesId = 2 },
new { HairdresserId = 1, HairdressingServicesId = 6 },
new { HairdresserId = 1, HairdressingServicesId = 7 },
new { HairdresserId = 1, HairdressingServicesId = 8 },
new { HairdresserId = 1, HairdressingServicesId = 9 },
new { HairdresserId = 1, HairdressingServicesId = 10 }
);
CustomerAppointmentSeedingData(modelBuilder, hairdressingServices, hairdressers, ageGroup);
}
private void CustomerAppointmentSeedingData(ModelBuilder modelBuilder,
List hairdressingServicesList,
List hairdressersList,
List ageGroups)
{
Console.WriteLine("Seeding CustomerAppointments...");
var random = new Random();
var customerAppointmentHairdressingServices = new List();
var customerAppointments = new List();
var statuses = Enum.GetValues(typeof(CustomerAppointmentStatus)).Cast().ToArray();
for (int i = 0; i < 1; i++)
{
// Select a random Hairdresser, AgeGroup, and Status
var hairdresser = hairdressersList[random.Next(hairdressersList.Count)];
var ageGroup = ageGroups[random.Next(ageGroups.Count)];
var status = statuses[random.Next(statuses.Length)];
// Select 1 to 3 random HairdressingServices
var selectedServices = hairdressingServicesList.OrderBy(x => random.Next()).Take(random.Next(1, 4)).ToList();
// Calculate the total duration by summing the durations of selected services
TimeSpan totalDuration = selectedServices.Aggregate(TimeSpan.Zero, (sum, service) => sum.Add(service.Duration));
// Random DateTime within the next 30 days
DateTime appointmentDateTime = DateTime.Now.AddDays(random.Next(1, 31)).AddHours(random.Next(9, 18)).AddMinutes(random.Next(0, 60));
// Create the CustomerAppointment entity
var customerAppointment = new CustomerAppointment
{
Id = i + 1,
Name = $"Name{i + 1}",
Surname = $"Surname{i + 1}",
Gender = (Gender)random.Next(0, 2), // Random gender (0 or 1)
AgeGroupId = ageGroup.Id,
HairdresserId = hairdresser.Id,
Duration = totalDuration,
Price = selectedServices.Sum(service => service.Price),
DateTime = appointmentDateTime,
PhoneNumber = $"+90 123 456 78{random.Next(10, 99)}",
EMail = $"customer{i + 1}@example.com",
CreatedBy = null, // Replace with actual IdentityUser if needed
Status = status
/*
Id = i + 1,
Name = $"Name",
Surname = $"Surname",
Gender = Gender.m, // Random gender (0 or 1)
AgeGroupId = 1,
HairdresserId = 1,
Duration = new TimeSpan(0,20,0),
Price = selectedServices.Sum(service => service.Price),
DateTime = new DateTime(new DateOnly(2025,1,1), new TimeOnly(13,30)),
PhoneNumber = $"+90 123 456 78 22",
EMail = $"customer@example.com",
CreatedBy = null, // Replace with actual IdentityUser if needed
Status = CustomerAppointmentStatus.AwaitingApproval
*/
};
customerAppointments.Add(customerAppointment);
// Seed the many-to-many relationship (CustomerAppointment HairdressingService)
foreach (var service in selectedServices)
{
customerAppointmentHairdressingServices.Add(
new { CustomerAppointmentId = customerAppointment.Id, HairdressingServicesId = service.Id }
);
}
}
modelBuilder.Entity().HasData(customerAppointments);
modelBuilder.Entity("CustomerAppointmentHairdressingServices").HasData(new { CustomerAppointmentId = 1, HairdressingServicesId = 1 },
new { CustomerAppointmentId = 1, HairdressingServicesId = 2 },
new { CustomerAppointmentId = 1, HairdressingServicesId = 4 });
//modelBuilder.Entity("CustomerAppointmentHairdressingServices").HasData(customerAppointmentHairdressingServices);
}
}
}
< /code>
Wenn ich alles von Hand so einsuche, funktioniert es: < /p>
Id = i + 1,
Name = $"Name",
Surname = $"Surname",
Gender = Gender.m, // Random gender (0 or 1)
AgeGroupId = 1,
HairdresserId = 1,
Duration = new TimeSpan(0,20,0),
Price = 100, //selectedServices.Sum(service => service.Price),
DateTime = new DateTime(new DateOnly(2025,1,1), new TimeOnly(13,30)),
PhoneNumber = $"+90 123 456 78 22",
EMail = $"customer@example.com",
CreatedBy = null, // Replace with actual IdentityUser if needed
Status = CustomerAppointmentStatus.AwaitingApproval
< /code>
Aber wenn ich nur den Preis zurück in < /p>
ändere Price = selectedServices.Sum(service => service.Price),
< /code>
Es gibt den gleichen Fehler. Was vermisse ich hier?
So beheben Sie das Datenbankaktualisierung an. ⇐ C#
Ein Treffpunkt für C#-Programmierer
1741524383
Anonymous
Ich versuche, Saatdaten zu erstellen. Wenn ich "Dotnet EF -Datenbank -Update" ausführe, erhalte ich den folgenden Fehler: < /p>
Build started...
Build succeeded.
System.InvalidOperationException: An error was generated for warning
'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning':
The model for context 'RepositoryContext' has pending changes. Add a
new migration before updating the database. This exception can be
suppressed or logged by passing event ID
'RelationalEventId.PendingModelChangesWarning' to the
'ConfigureWarnings' method in 'DbContext.OnConfiguring' or
'AddDbContext'.
at Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition`1.Log[TLoggerCategory](IDiagnosticsLogger`1 logger, TParam arg)
at Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggerExtensions.PendingModelChangesWarning(IDiagnosticsLogger`1 diagnostics, Type contextType)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.c__DisplayClass0_0.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
< /code>
Es wurde ein Fehler für die Warnung generiert. Fügen Sie eine neue Migration hinzu, bevor Sie die Datenbank aktualisieren. Diese Ausnahme kann
unterdrückt oder protokolliert werden, indem Ereignis -ID
'relationalEvent.PendingModelChangesWarning 'an die Methode
' configureWarnings 'in' dbcontext.onconfiguring 'oder
'addbcontext. & $ -Ccontext.Br /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /blockt, eingelegt werden. : < /p>
using Entities.Models;
using Entities.Models.Enums;
using Microsoft.EntityFrameworkCore;
namespace Repositories
{
public class RepositoryContext : DbContext
{
public DbSet AgeGroups { get; set; }
public DbSet Hairdressers { get; set; }
public DbSet HairdressingServices { get; set; }
public DbSet CustomerAppointments { get; set; }
public DbSet HairdressingServiceLocalizations { get; set; }
public RepositoryContext(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity().HasMany(x => x.AgeGroups)
.WithMany(y => y.HairdressingService)
.UsingEntity("HairdressingServiceAgeGroups");
modelBuilder.Entity().HasOne(l => l.HairdressingService)
.WithMany(h => h.Localizations)
.HasForeignKey(l => l.HairdressingServiceId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity().HasMany(x => x.HairdressingServices)
.WithMany(y => y.Hairdresser)
.UsingEntity("HairdresserHairdressingServices");
modelBuilder.Entity().HasMany(c => c.HairdressingServices)
.WithMany(h => h.CustomerAppointment)
.UsingEntity("CustomerAppointmentHairdressingServices");
SeedingData(modelBuilder);
}
private void SeedingData(ModelBuilder modelBuilder)
{
var ageGroup1 = new AgeGroup { Id = 1, MinAge = 0, MaxAge = 17 };
var ageGroup2 = new AgeGroup { Id = 2, MinAge = 18, MaxAge = 75 };
var ageGroup3 = new AgeGroup { Id = 3, MinAge = 76, MaxAge = 125 };
var ageGroup = new List();
ageGroup.Add(ageGroup1);
ageGroup.Add(ageGroup2);
var hairdressingService1 = new HairdressingService { Id = 1, Name = "HairCut", Genders = { Gender.m }, Duration = new TimeSpan(0, 20, 0), Price = 100, Status = true };
var hairdressingService2 = new HairdressingService { Id = 2, Name = "RazorShave", Genders = { Gender.m }, Duration = new TimeSpan(0, 40, 0), Price = 200, Status = true };
var hairdressingService3 = new HairdressingService { Id = 3, Name = "HairColoring", Genders = { Gender.m }, Duration = new TimeSpan(0, 60, 0), Price = 300, Status = true };
var hairdressingService4 = new HairdressingService { Id = 4, Name = "BrowShaping", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 80, 0), Price = 400, Status = true };
var hairdressingService5 = new HairdressingService { Id = 5, Name = "BeardGrooming", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 100, 0), Price = 500, Status = true };
var hairdressingService6 = new HairdressingService { Id = 6, Name = "ChildShave", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 120, 0), Price = 600, Status = true };
var hairdressingService7 = new HairdressingService { Id = 7, Name = "PermHair", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 140, 0), Price = 700, Status = false };
var hairdressingService8 = new HairdressingService { Id = 8, Name = "Manicure", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 150, 0), Price = 800, Status = false };
var hairdressingService9 = new HairdressingService { Id = 9, Name = "Pedicure", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 160, 0), Price = 900, Status = false };
var hairdressingService10 = new HairdressingService { Id = 10, Name = "GroomsCut", Genders = { Gender.m }, Duration = new TimeSpan(0, 180, 0), Price = 1000, Status = true };
var hairdressingService11 = new HairdressingService { Id = 11, Name = "Makeup(Bride)", Genders = { Gender.f }, Duration = new TimeSpan(0, 200, 0), Price = 1100, Status = false };
List hairdressingServices = new List();
hairdressingServices.Add(hairdressingService1);
hairdressingServices.Add(hairdressingService2);
hairdressingServices.Add(hairdressingService3);
hairdressingServices.Add(hairdressingService4);
hairdressingServices.Add(hairdressingService5);
hairdressingServices.Add(hairdressingService6);
hairdressingServices.Add(hairdressingService7);
hairdressingServices.Add(hairdressingService8);
hairdressingServices.Add(hairdressingService9);
hairdressingServices.Add(hairdressingService10);
hairdressingServices.Add(hairdressingService11);
var hairdresser1 = new Hairdresser { Id = 1, IdentityUserId = "1", Name = "Aydın", Surname = "Sevim", CanTakeClients = true };
var hairdresser2 = new Hairdresser { Id = 2, IdentityUserId = "2", Name = "Alpay", Surname = "Aydıngüler", CanTakeClients = true };
var hairdresser3 = new Hairdresser { Id = 3, IdentityUserId = "2", Name = "Deniz", Surname = "Dağ", CanTakeClients = false };
var hairdressers = new List();
hairdressers.Add(hairdresser1);
hairdressers.Add(hairdresser2);
hairdressers.Add(hairdresser3);
modelBuilder.Entity().HasData(ageGroup1, ageGroup2, ageGroup3);
modelBuilder.Entity().HasData(hairdressingServices);
modelBuilder.Entity().HasData(hairdressers);
modelBuilder.Entity("HairdressingServiceAgeGroups").HasData(
new { HairdressingServiceId = 1, AgeGroupsId = 1 },
new { HairdressingServiceId = 2, AgeGroupsId = 2 },
new { HairdressingServiceId = 3, AgeGroupsId = 1 },
new { HairdressingServiceId = 3, AgeGroupsId = 2 },
new { HairdressingServiceId = 4, AgeGroupsId = 1 },
new { HairdressingServiceId = 5, AgeGroupsId = 1 },
new { HairdressingServiceId = 5, AgeGroupsId = 2 },
new { HairdressingServiceId = 6, AgeGroupsId = 1 },
new { HairdressingServiceId = 7, AgeGroupsId = 2 },
new { HairdressingServiceId = 8, AgeGroupsId = 2 },
new { HairdressingServiceId = 9, AgeGroupsId = 2 },
new { HairdressingServiceId = 10, AgeGroupsId = 2 },
new { HairdressingServiceId = 11, AgeGroupsId = 2 }
);
modelBuilder.Entity().HasData(// HairCut
new HairdressingServiceLocalization { Id = 1, HairdressingServiceId = 1, Language = "en-GB", Name = "Hair Cut" },
new HairdressingServiceLocalization { Id = 2, HairdressingServiceId = 1, Language = "tr-TR", Name = "Saç Kesimi" },
// RazorShave
new HairdressingServiceLocalization { Id = 3, HairdressingServiceId = 2, Language = "en-GB", Name = "Razor Shave" },
new HairdressingServiceLocalization { Id = 4, HairdressingServiceId = 2, Language = "tr-TR", Name = "Jilet Traşı" },
// HairColoring
new HairdressingServiceLocalization { Id = 5, HairdressingServiceId = 3, Language = "en-GB", Name = "Hair Coloring" },
new HairdressingServiceLocalization { Id = 6, HairdressingServiceId = 3, Language = "tr-TR", Name = "Saç Boyama" },
// BrowShaping
new HairdressingServiceLocalization { Id = 7, HairdressingServiceId = 4, Language = "en-GB", Name = "Brow Shaping" },
new HairdressingServiceLocalization { Id = 8, HairdressingServiceId = 4, Language = "tr-TR", Name = "Kaş Şekillendirme" },
// BeardGrooming
new HairdressingServiceLocalization { Id = 9, HairdressingServiceId = 5, Language = "en-GB", Name = "Beard Grooming" },
new HairdressingServiceLocalization { Id = 10, HairdressingServiceId = 5, Language = "tr-TR", Name = "Sakal Bakımı" },
// ChildShave
new HairdressingServiceLocalization { Id = 11, HairdressingServiceId = 6, Language = "en-GB", Name = "Child Shave" },
new HairdressingServiceLocalization { Id = 12, HairdressingServiceId = 6, Language = "tr-TR", Name = "Çocuk Tıraşı" },
// PermHair
new HairdressingServiceLocalization { Id = 13, HairdressingServiceId = 7, Language = "en-GB", Name = "Perm Hair" },
new HairdressingServiceLocalization { Id = 14, HairdressingServiceId = 7, Language = "tr-TR", Name = "Perma Saç" },
// Manicure
new HairdressingServiceLocalization { Id = 15, HairdressingServiceId = 8, Language = "en-GB", Name = "Manicure" },
new HairdressingServiceLocalization { Id = 16, HairdressingServiceId = 8, Language = "tr-TR", Name = "Manikür" },
// Pedicure
new HairdressingServiceLocalization { Id = 17, HairdressingServiceId = 9, Language = "en-GB", Name = "Pedicure" },
new HairdressingServiceLocalization { Id = 18, HairdressingServiceId = 9, Language = "tr-TR", Name = "Pedikür" },
// GroomsCut
new HairdressingServiceLocalization { Id = 19, HairdressingServiceId = 10, Language = "en-GB", Name = "Groom's Cut" },
new HairdressingServiceLocalization { Id = 20, HairdressingServiceId = 10, Language = "tr-TR", Name = "Damat Kesimi" },
// Makeup(Bride)
new HairdressingServiceLocalization { Id = 21, HairdressingServiceId = 11, Language = "en-GB", Name = "Makeup (Bride)" },
new HairdressingServiceLocalization { Id = 22, HairdressingServiceId = 11, Language = "tr-TR", Name = "Makyaj (Gelin)" });
modelBuilder.Entity("HairdresserHairdressingServices").HasData(
new { HairdresserId = 1, HairdressingServicesId = 1 },
new { HairdresserId = 1, HairdressingServicesId = 2 },
new { HairdresserId = 1, HairdressingServicesId = 3 },
new { HairdresserId = 1, HairdressingServicesId = 4 },
new { HairdresserId = 1, HairdressingServicesId = 5 },
new { HairdresserId = 2, HairdressingServicesId = 2 },
new { HairdresserId = 1, HairdressingServicesId = 6 },
new { HairdresserId = 1, HairdressingServicesId = 7 },
new { HairdresserId = 1, HairdressingServicesId = 8 },
new { HairdresserId = 1, HairdressingServicesId = 9 },
new { HairdresserId = 1, HairdressingServicesId = 10 }
);
CustomerAppointmentSeedingData(modelBuilder, hairdressingServices, hairdressers, ageGroup);
}
private void CustomerAppointmentSeedingData(ModelBuilder modelBuilder,
List hairdressingServicesList,
List hairdressersList,
List ageGroups)
{
Console.WriteLine("Seeding CustomerAppointments...");
var random = new Random();
var customerAppointmentHairdressingServices = new List();
var customerAppointments = new List();
var statuses = Enum.GetValues(typeof(CustomerAppointmentStatus)).Cast().ToArray();
for (int i = 0; i < 1; i++)
{
// Select a random Hairdresser, AgeGroup, and Status
var hairdresser = hairdressersList[random.Next(hairdressersList.Count)];
var ageGroup = ageGroups[random.Next(ageGroups.Count)];
var status = statuses[random.Next(statuses.Length)];
// Select 1 to 3 random HairdressingServices
var selectedServices = hairdressingServicesList.OrderBy(x => random.Next()).Take(random.Next(1, 4)).ToList();
// Calculate the total duration by summing the durations of selected services
TimeSpan totalDuration = selectedServices.Aggregate(TimeSpan.Zero, (sum, service) => sum.Add(service.Duration));
// Random DateTime within the next 30 days
DateTime appointmentDateTime = DateTime.Now.AddDays(random.Next(1, 31)).AddHours(random.Next(9, 18)).AddMinutes(random.Next(0, 60));
// Create the CustomerAppointment entity
var customerAppointment = new CustomerAppointment
{
Id = i + 1,
Name = $"Name{i + 1}",
Surname = $"Surname{i + 1}",
Gender = (Gender)random.Next(0, 2), // Random gender (0 or 1)
AgeGroupId = ageGroup.Id,
HairdresserId = hairdresser.Id,
Duration = totalDuration,
Price = selectedServices.Sum(service => service.Price),
DateTime = appointmentDateTime,
PhoneNumber = $"+90 123 456 78{random.Next(10, 99)}",
EMail = $"customer{i + 1}@example.com",
CreatedBy = null, // Replace with actual IdentityUser if needed
Status = status
/*
Id = i + 1,
Name = $"Name",
Surname = $"Surname",
Gender = Gender.m, // Random gender (0 or 1)
AgeGroupId = 1,
HairdresserId = 1,
Duration = new TimeSpan(0,20,0),
Price = selectedServices.Sum(service => service.Price),
DateTime = new DateTime(new DateOnly(2025,1,1), new TimeOnly(13,30)),
PhoneNumber = $"+90 123 456 78 22",
EMail = $"customer@example.com",
CreatedBy = null, // Replace with actual IdentityUser if needed
Status = CustomerAppointmentStatus.AwaitingApproval
*/
};
customerAppointments.Add(customerAppointment);
// Seed the many-to-many relationship (CustomerAppointment HairdressingService)
foreach (var service in selectedServices)
{
customerAppointmentHairdressingServices.Add(
new { CustomerAppointmentId = customerAppointment.Id, HairdressingServicesId = service.Id }
);
}
}
modelBuilder.Entity().HasData(customerAppointments);
modelBuilder.Entity("CustomerAppointmentHairdressingServices").HasData(new { CustomerAppointmentId = 1, HairdressingServicesId = 1 },
new { CustomerAppointmentId = 1, HairdressingServicesId = 2 },
new { CustomerAppointmentId = 1, HairdressingServicesId = 4 });
//modelBuilder.Entity("CustomerAppointmentHairdressingServices").HasData(customerAppointmentHairdressingServices);
}
}
}
< /code>
Wenn ich alles von Hand so einsuche, funktioniert es: < /p>
Id = i + 1,
Name = $"Name",
Surname = $"Surname",
Gender = Gender.m, // Random gender (0 or 1)
AgeGroupId = 1,
HairdresserId = 1,
Duration = new TimeSpan(0,20,0),
Price = 100, //selectedServices.Sum(service => service.Price),
DateTime = new DateTime(new DateOnly(2025,1,1), new TimeOnly(13,30)),
PhoneNumber = $"+90 123 456 78 22",
EMail = $"customer@example.com",
CreatedBy = null, // Replace with actual IdentityUser if needed
Status = CustomerAppointmentStatus.AwaitingApproval
< /code>
Aber wenn ich nur den Preis zurück in < /p>
ändere Price = selectedServices.Sum(service => service.Price),
< /code>
Es gibt den gleichen Fehler. Was vermisse ich hier?
-
- Similar Topics
- Replies
- Views
- Last post
-
-
So beheben Sie den PendingModelChangesWarning-Fehler bei der Datenbankaktualisierung
by Guest » » in C#Ich versuche, Seeding-Daten zu erstellen. Wenn ich „dotnet ef Database Update“ ausführe, erhalte ich die folgende Fehlermeldung:
Build started...
Build succeeded.
System.InvalidOperationException:... - 0 Replies
- 15 Views
-
Last post by Guest
-
-
-
So beheben Sie „Kommunikationsverbindungsfehler, das letzte Paket, das erfolgreich an den Server gesendet wurde, liegt 0
by Guest » » in MySqlHallo, ich versuche, eine Spring Boot-Anwendung mit Docker-Compose bereitzustellen.
Beim Ausführen der Datei mit dem Befehl Docker-Compose Up -d ist jedoch der folgende Fehler aufgetreten.
FEHLER 1... - 0 Replies
- 12 Views
-
Last post by Guest
-
-
-
Wie kann ich das Problem beheben, dass die Anfrage das Limit von 10 internen Weiterleitungen überschritten hat (eher ein
by Guest » » in PhpIch richte über MAMP eine lokale Umgebung einer Site ein, die ich vor ein paar Monaten aus dem Internet entfernt habe, um einige alte Funktionen auf der Site anzuzeigen, und erhalte derzeit die... - 0 Replies
- 22 Views
-
Last post by Guest
-
-
-
Wie kann ich das Problem des Anmeldes, das in meinem System fehlschlägt, beheben? [geschlossen]
by Guest » » in PhpIch habe ein Problem mit einem Inventarsystem, das ich programmiere. Das Problem ist, dass die Anmeldung nicht funktionieren möchte, sondern das System nicht eingibt, egal wie viel ich die Daten... - 0 Replies
- 5 Views
-
Last post by Guest
-
-
-
Wie kann ich das Problem des Anmeldes, das in meinem System fehlschlägt, beheben? [geschlossen]
by Guest » » in CSSIch habe ein Problem mit einem Inventarsystem, das ich programmiere. Das Problem ist, dass die Anmeldung nicht funktionieren möchte, sondern das System nicht eingibt, egal wie viel ich die Daten... - 0 Replies
- 5 Views
-
Last post by Guest
-