-
Notifications
You must be signed in to change notification settings - Fork 0
/
Context.cs
46 lines (39 loc) · 1.65 KB
/
Context.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
42
43
44
45
46
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
using ConfigurationLibrary.Classes;
using EntityFrameworkCore.Models;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
namespace EntityFrameworkCore.Data;
public partial class Context : DbContext
{
public Context()
{
}
public virtual DbSet<Contact> Contact { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(ConfigurationHelper.ConnectionString())
.EnableSensitiveDataLogging()
.LogTo(message => Debug.WriteLine(message), LogLevel.Information)
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Contact>(entity =>
{
entity.Property(e => e.BirthDate)
.HasColumnType("date");
entity.Property(e => e.BirthYear)
.HasComment("Computes birth year from BirthDate")
.HasComputedColumnSql("(datepart(year,[BirthDate]))", false);
entity.Property(e => e.FullName)
.HasComputedColumnSql("(([FirstName]+' ')+[LastName])", false);
entity.Property(e => e.YearsOld)
.HasComment("Computes years old from BirthDate")
.HasComputedColumnSql("(datediff(year,[BirthDate],getdate()))", false);
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}