-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
68 lines (58 loc) · 1.98 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Microsoft.EntityFrameworkCore;
using Npgsql;
using System;
using System.Linq;
namespace EFTestDate
{
class MyTable
{
public int Id { get; set; }
public DateTimeOffset OffsetDate { get; set; }
public DateTime RegularDate { get; set; }
}
class TestContext: DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
const string connectionString = "Server=127.0.0.1;Port=5432;Database=MyTest;User Id=<USER>;Password=<PASSWORD>;";
optionsBuilder.UseNpgsql(connectionString);
}
public DbSet<MyTable> MyTable { get; set; }
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting...");
var context = new TestContext();
context.Database.Migrate();
// Query against the int column - control test
ExecuteQuery(
context.MyTable.Where(t => t.Id == 1)
, 1);
// Query against DateTimeOffset column
ExecuteQuery(
context.MyTable.Where(t => t.OffsetDate == new DateTime(2017, 1, 1))
, 2);
// Query against DateTime column
ExecuteQuery(
context.MyTable.Where(t => t.RegularDate == new DateTime(2017, 1, 1))
, 3);
Console.WriteLine("Finished.");
Console.ReadKey();
}
static void ExecuteQuery(IQueryable<MyTable> query, int testNumber)
{
try
{
var list = query.ToList();
Console.WriteLine($"- Success test {testNumber} count: {list.Count}\r\n");
}
catch (PostgresException ex)
{
Console.WriteLine($"- Failure test {testNumber} Exception thrown for statement: \r\n\r\n{ex.Statement.ToString()}\r\n");
}
}
}
}