BuchhaltungBlazor/Data/EntityConfiguration.cs

49 lines
2.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Buchhaltung;
public class BookingConfiguration : IEntityTypeConfiguration<Booking> {
public void Configure(EntityTypeBuilder<Booking> builder) {
builder.HasKey(booking => booking.Id);
// bookingEntity.Ignore(booking => booking.Category);
// bookingEntity.Ignore(booking => booking.SubCategory);
builder.HasOne(booking => booking.Category).WithMany(category => category.Bookings).HasForeignKey(booking => booking.CategoryId);
builder.HasOne(booking => booking.SubCategory).WithMany(category => category.Bookings).HasForeignKey(booking => booking.SubCategoryId);
builder.Property(booking => booking.BookingDay);
builder.Property(booking => booking.Valuta);
builder.Property(booking => booking.Typ);
builder.Property(booking => booking.Details);
builder.Property(booking => booking.Amount);
}
}
public class CategoryConfiguration : IEntityTypeConfiguration<Category> {
public void Configure(EntityTypeBuilder<Category> builder) {
builder.HasKey(category => category.Id);
builder.Ignore(category => category.Bookings);
// categoryEntity.HasMany(category => category.Bookings)
// .WithOne(booking => booking.Category)
// .HasForeignKey(booking => booking.CategoryId);
builder.Property(category => category.Name);
}
}
public class SubCategoryConfiguration : IEntityTypeConfiguration<SubCategory> {
public void Configure(EntityTypeBuilder<SubCategory> builder) {
builder.HasKey(subCategory => subCategory.Id);
builder.Ignore(subCategory => subCategory.Bookings);
// categoryEntity.HasMany(subCategory => subCategory.Bookings)
// .WithOne(booking => booking.SubCategory)
// .HasForeignKey(booking => booking.SubCategoryId);
builder.Property(subCategory => subCategory.Name);
}
}