-
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathProgram.cs
More file actions
32 lines (27 loc) · 1.32 KB
/
Program.cs
File metadata and controls
32 lines (27 loc) · 1.32 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
using System;
using System.Linq;
using ConsoleAppEF2.Database;
namespace ConsoleAppEF31
{
class Program
{
static void Main(string[] args)
{
var context = new TestContext();
// context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var dateDeleted = new DateTime(2019, 2, 2);
var dateLastModified = new DateTime(2018, 1, 15);
if (!context.Cars.Any())
{
context.Cars.Add(new Car { Brand = "Ford", Color = "Blue", Vin = "yes", Year = "2017", DateLastModified = dateLastModified, DateDeleted = dateDeleted });
context.Cars.Add(new Car { Brand = "Fiat", Color = "Red", Vin = "yes", Year = "2016", DateLastModified = dateLastModified.AddDays(1) });
context.Cars.Add(new Car { Brand = "Alfa", Color = "Black", Vin = "no", Year = "1979", DateLastModified = dateLastModified.AddDays(2) });
context.Cars.Add(new Car { Brand = "Alfa", Color = "Black", Vin = "a%bc", Year = "1979", DateLastModified = dateLastModified.AddDays(3) }); ;
context.SaveChanges();
}
var selectNullableDateTime = context.Cars.FirstOrDefault(c => c.DateDeleted == dateDeleted);
Console.WriteLine(selectNullableDateTime.Key);
}
}
}