-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
47 lines (39 loc) · 1.3 KB
/
Program.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
47
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
namespace MRE.EFCore5.HasDbFunction
{
class Program
{
static void Main(string[] args)
{
var connectionString = @"server=(localdb)\MSSQLLocalDB;database=test;trusted_connection=true;multipleactiveresultsets=true";
var options = new DbContextOptionsBuilder<Context>()
.UseSqlServer(connectionString)
.Options;
var context = new Context(options);
context.Database.EnsureCreated();
if (!context.Foos.Any())
{
context.Foos.Add(new Foo() { Created = DateTimeOffset.UtcNow });
context.SaveChanges();
}
try
{
var foos = from f in context.Foos
select new
{
Created = f.Created.ToTimeZone("E. Australia Standard Time")
};
foreach (var f in foos)
{
Console.WriteLine($"Foo => {f.Created}");
}
}
catch (NotImplementedException ex)
{
Console.Write($"This shouldn't happen => {ex.Message}");
}
}
}
}