-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsupContext.cs
41 lines (31 loc) · 1.19 KB
/
AsupContext.cs
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
using Entity_Framework.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
namespace Entity_Framework
{
public class AsupContext : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<Materials> Materials { get; set; }
public DbSet<Vendor> Vendor { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=helloappdb;Trusted_Connection=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ProductMaterials>()
.HasKey(t => new { t.ProductId, t.MaterialId });
modelBuilder.Entity<ProductMaterials>()
.HasOne(x => x.Product)
.WithMany(y => y.ProductMaterials)
.HasForeignKey(x => x.ProductId);
modelBuilder.Entity<ProductMaterials>()
.HasOne(x => x.Material)
.WithMany(y => y.ProductMaterials)
.HasForeignKey(x => x.MaterialId);
}
}
}