Repository navigation
Expand file tree
/
Copy pathSampleDbContext.cs
More file actions
42 lines (38 loc) · 1.73 KB
/
Copy pathSampleDbContext.cs
File metadata and controls
42 lines (38 loc) · 1.73 KB
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
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntityFrameworkCore.Projectables.Extensions;
using EntityFrameworkCore.Projectables.Infrastructure;
using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkCore.Projectables.FunctionalTests.Helpers
{
public class SampleDbContext<TEntity> : DbContext
where TEntity : class
{
readonly CompatibilityMode _compatibilityMode;
readonly QueryTrackingBehavior _queryTrackingBehavior;
readonly bool _populateSettableProperties;
public SampleDbContext(CompatibilityMode compatibilityMode = CompatibilityMode.Full, QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll, bool populateSettableProperties = true)
{
_compatibilityMode = compatibilityMode;
_queryTrackingBehavior = queryTrackingBehavior;
_populateSettableProperties = populateSettableProperties;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\v11.0;Integrated Security=true"); // Fake connection string as we're actually never connecting
optionsBuilder.UseProjectables(options => {
options.CompatibilityMode(_compatibilityMode); // Needed by our ComplexModelTests
options.PopulateSettableProperties(_populateSettableProperties);
});
optionsBuilder.UseQueryTrackingBehavior(_queryTrackingBehavior);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TEntity>();
}
}
}