Spaces:
Sleeping
Sleeping
File size: 7,519 Bytes
87c9973 c596926 87c9973 c596926 87c9973 c596926 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
namespace Database.Models;
public partial class LibraryManagementContext : DbContext
{
public LibraryManagementContext()
{
}
public LibraryManagementContext(DbContextOptions<LibraryManagementContext> options)
: base(options)
{
}
public virtual DbSet<Book> Books { get; set; }
public virtual DbSet<Borrowing> Borrowings { get; set; }
public virtual DbSet<Category> Categories { get; set; }
public virtual DbSet<Membership> Memberships { get; set; }
public virtual DbSet<User> Users { get; set; }
public virtual DbSet<UserSubscription> UserSubscriptions { get; set; }
public virtual DbSet<Wishlist> Wishlists { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
=> optionsBuilder.UseSqlServer("Server=DESKTOP-BP9A061;Database=LibraryManagement;User Id=sa;Password=sasa@123;TrustServerCertificate=True;");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Book>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__Books__3214EC07AE1974C8");
entity.HasIndex(e => e.Isbn, "UQ__Books__447D36EA79CF66CE").IsUnique();
entity.Property(e => e.Author).HasMaxLength(100);
entity.Property(e => e.CreatedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.Property(e => e.IsActive).HasDefaultValue(true);
entity.Property(e => e.Isbn)
.HasMaxLength(20)
.HasColumnName("ISBN");
entity.Property(e => e.Status)
.HasMaxLength(20)
.HasDefaultValue("Available");
entity.Property(e => e.Title).HasMaxLength(200);
entity.Property(e => e.TotalCopies).HasDefaultValue(1);
entity.Property(e => e.AvailableCopies).HasDefaultValue(1);
entity.Property(e => e.UpdatedAt).HasColumnType("datetime");
entity.HasMany(d => d.Categories).WithMany(p => p.Books)
.UsingEntity<Dictionary<string, object>>(
"BookCategory",
r => r.HasOne<Category>().WithMany()
.HasForeignKey("CategoryId")
.HasConstraintName("FK_BookCategories_Categories"),
l => l.HasOne<Book>().WithMany()
.HasForeignKey("BookId")
.HasConstraintName("FK_BookCategories_Books"),
j =>
{
j.HasKey("BookId", "CategoryId").HasName("PK__BookCate__9C7051A74E7D221D");
j.ToTable("BookCategories");
});
});
modelBuilder.Entity<Borrowing>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__Borrowin__3214EC07EA26D8CD");
entity.Property(e => e.BorrowDate)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.Property(e => e.DueDate).HasColumnType("datetime");
entity.Property(e => e.FineAmount).HasColumnType("decimal(10, 2)");
entity.Property(e => e.ReturnDate).HasColumnType("datetime");
entity.Property(e => e.Status)
.HasMaxLength(20)
.HasDefaultValue("Active");
entity.HasOne(d => d.Book).WithMany(p => p.Borrowings)
.HasForeignKey(d => d.BookId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Borrowings_Books");
entity.HasOne(d => d.User).WithMany(p => p.Borrowings)
.HasForeignKey(d => d.UserId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Borrowings_Users");
});
modelBuilder.Entity<Category>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__Categori__3214EC0751B5797D");
entity.HasIndex(e => e.Name, "UQ__Categori__737584F622B16D3A").IsUnique();
entity.Property(e => e.Name).HasMaxLength(100);
});
modelBuilder.Entity<Membership>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__Membersh__3214EC07A6F5A55F");
entity.HasIndex(e => e.Type, "IX_Memberships_Type").IsUnique();
entity.Property(e => e.Price).HasColumnType("decimal(10, 2)");
entity.Property(e => e.Type).HasMaxLength(50);
});
modelBuilder.Entity<User>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__Users__3214EC0771D7BED2");
entity.HasIndex(e => e.Email, "UQ__Users__A9D10534F91FFF73").IsUnique();
entity.Property(e => e.Address).HasMaxLength(255);
entity.Property(e => e.CreatedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.Property(e => e.Email).HasMaxLength(100);
entity.Property(e => e.FullName).HasMaxLength(100);
entity.Property(e => e.IsActive).HasDefaultValue(true);
entity.Property(e => e.PhoneNumber).HasMaxLength(20);
entity.Property(e => e.Role)
.HasMaxLength(20)
.HasDefaultValue("Member");
entity.Property(e => e.StudentId).HasMaxLength(20);
entity.Property(e => e.SuspensionEndDate).HasColumnType("datetime");
entity.Property(e => e.UpdatedAt).HasColumnType("datetime");
});
modelBuilder.Entity<UserSubscription>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__UserSubs__3214EC07E3FBC0EC");
entity.Property(e => e.ExpiryDate).HasColumnType("datetime");
entity.Property(e => e.IsActive).HasDefaultValue(true);
entity.Property(e => e.StartDate).HasColumnType("datetime");
entity.HasOne(d => d.Membership).WithMany(p => p.UserSubscriptions)
.HasForeignKey(d => d.MembershipId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_UserSubscriptions_Memberships");
entity.HasOne(d => d.User).WithMany(p => p.UserSubscriptions)
.HasForeignKey(d => d.UserId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_UserSubscriptions_Users");
});
modelBuilder.Entity<Wishlist>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__Wishlist__3214EC07F63D8F81");
entity.HasOne(d => d.Book).WithMany(p => p.Wishlists)
.HasForeignKey(d => d.BookId)
.HasConstraintName("FK_Wishlists_Books");
entity.HasOne(d => d.User).WithMany(p => p.Wishlists)
.HasForeignKey(d => d.UserId)
.HasConstraintName("FK_Wishlists_Users");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
|