Closed
Description
openedon Aug 3, 2021
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
public partial class EFCoreSampleContext : DbContext
{
public EFCoreSampleContext()
{
}
public EFCoreSampleContext(DbContextOptions<EFCoreSampleContext> options)
: base(options)
{
}
public virtual DbSet<Customer> Customers { get; set; } = null!;
public virtual DbSet<Order> Orders { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
#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 http://go.microsoft.com/fwlink/?LinkId=723263.
optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=EFCoreSample");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
modelBuilder.Entity<Order>(entity =>
{
entity.ToTable("Order");
entity.HasIndex(e => e.CustomerId, "IX_Order_CustomerId");
entity.HasOne(d => d.Customer)
.WithMany(p => p.Orders)
.HasForeignKey(d => d.CustomerId);
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment