Created
May 7, 2020 01:28
-
-
Save StefanRiedmann/2942bd39224a54dfc6fe466590ac0cb0 to your computer and use it in GitHub Desktop.
GardenContext with view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GardenContext : DbContext | |
{ | |
public DbSet<Garden> Gardens { get; set; } | |
public DbSet<Bed> Beds { get; set; } | |
public DbSet<Crop> Crops { get; set; } | |
public DbSet<CropAssignment> CropAssignments { get; set; } | |
public DbSet<GardenInfo> GardenInfos { get; set; } | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder.Entity<GardenInfo>(d => | |
{ | |
d.HasKey("GardenId", "Year"); | |
d.ToView("View_GardenInfos"); | |
d.HasOne("Garden").WithMany("GardenInfos"); | |
}); | |
} | |
protected override void OnConfiguring(DbContextOptionsBuilder options) | |
=> options.UseSqlServer("Server=localhost,1433; Database=GardenDb1;User=sa; Password=1StrongPassword!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment