您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WsDbContext.cs 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Microsoft.EntityFrameworkCore;
  2. using WebApiWebSem.DataAccess.Models;
  3. namespace WebApiWebSem.DataAccess
  4. {
  5. public partial class WsDbContext : DbContext
  6. {
  7. public WsDbContext(DbContextOptions options) :base(options)
  8. {
  9. }
  10. protected override void OnModelCreating(ModelBuilder modelBuilder)
  11. {
  12. modelBuilder.Entity<articles>()
  13. .HasKey(c => new { c.id });
  14. modelBuilder.Entity<articles>()
  15. .Property(e => e.created_at)
  16. .HasDefaultValueSql("now_utc()");
  17. modelBuilder.Entity<articles_fields>()
  18. .HasKey(c => new { c.article_id, c.property });
  19. modelBuilder.Entity<articles_fields>()
  20. .HasOne(e => e.fk_articles)
  21. .WithMany(e => e.articles_fields_fk)
  22. .HasForeignKey("article_id")
  23. .HasConstraintName("articles_fields_article_id_fkey");
  24. }
  25. public virtual DbSet<articles> articles { get; set; }
  26. public virtual DbSet<articles_fields> articles_fields { get; set; }
  27. }
  28. }