Revize ebb51a7f
Přidáno uživatelem Vojtěch Bartička před více než 2 roky(ů)
Backend/Core/Contexts/DatabaseContext.cs | ||
---|---|---|
1 | 1 |
using Core.Entities; |
2 | 2 |
using Microsoft.EntityFrameworkCore; |
3 |
using Microsoft.Extensions.Configuration; |
|
3 | 4 |
using System; |
4 | 5 |
using System.Collections.Generic; |
5 | 6 |
using System.Linq; |
... | ... | |
10 | 11 |
{ |
11 | 12 |
public class DatabaseContext : DbContext |
12 | 13 |
{ |
14 |
private readonly IConfiguration _configuration; |
|
15 |
|
|
16 |
public DatabaseContext(IConfiguration configuration) |
|
17 |
{ |
|
18 |
_configuration = configuration; |
|
19 |
} |
|
20 |
|
|
13 | 21 |
public DbSet<DocumentContent> DocumentContents { get; set; } |
14 | 22 |
public DbSet<Document> Documents { get; set; } |
15 | 23 |
public DbSet<User> Users { get; set; } |
... | ... | |
23 | 31 |
|
24 | 32 |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) |
25 | 33 |
{ |
26 |
optionsBuilder.UseNpgsql("Host=localhost:5432;Database=dbo;Username=myuser;Password=password", b => b.MigrationsAssembly("RestAPI")); |
|
27 |
} |
|
28 |
|
|
29 |
protected override void OnModelCreating(ModelBuilder modelBuilder) |
|
30 |
{ |
|
31 |
/* modelBuilder.Entity<AnnotationClass>() |
|
32 |
.HasOne(ac => ac.Annotation) |
|
33 |
.WithMany(a => a.Classes) |
|
34 |
.HasForeignKey(ac => ac.AnnotationId); |
|
35 |
modelBuilder.Entity<AnnotationClass>() |
|
36 |
.HasOne(ac => ac.Class) |
|
37 |
.WithMany(c => c.Annotations) |
|
38 |
.HasForeignKey(ac => ac.ClassId);*/ |
|
34 |
optionsBuilder.UseNpgsql(_configuration["ConnectionString"], b => b.MigrationsAssembly("RestAPI")); |
|
39 | 35 |
} |
40 | 36 |
} |
41 | 37 |
} |
Také k dispozici: Unified diff
Added seeding, cleaned up code