-
-
Notifications
You must be signed in to change notification settings - Fork 224
/
Program.cs
57 lines (51 loc) · 2.12 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
using System;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using Newtonsoft.Json;
namespace ConsoleAppEF1
{
class Program
{
static void Main(string[] args)
{
using (var db = new MyDbContext())
{
var all = new
{
test1 = new List<int> { 1, 2, 3 }.ToDynamicList(typeof(int)),
test2 = new List<dynamic> { 4, 5, 6 }.ToDynamicList(typeof(int)),
test3 = new List<object> { 7, 8, 9 }.ToDynamicList(typeof(int))
};
Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));
var persons = new List<Person>
{
new Person { Name = "a", Age = 18, Address = new Address { Street = "s1" } },
new Person { Name = "b", Age = 19, Address = new Address { Street = "s2" } },
new Person { Name = "c", Age = 20, Address = new Address { Street = "s3" } },
};
// Database
bool deleted = db.Database.EnsureDeleted();
Console.WriteLine("Database is deleted = {0}", deleted);
if (db.Database.EnsureCreated())
{
Console.WriteLine("Database is created");
persons.ForEach(p => db.Add(p));
db.SaveChanges();
}
Console.WriteLine(new string('-', 80));
var result1 = db.Persons.Where("Age > 17").OrderBy("Name desc");
foreach (var person in result1)
{
Console.WriteLine(JsonConvert.SerializeObject(person, Formatting.Indented));
}
Console.WriteLine(new string('-', 80));
var result2 = db.Persons.Where("Age > 17").OrderBy("Address.Street");
foreach (var person in result2)
{
Console.WriteLine(JsonConvert.SerializeObject(person, Formatting.Indented));
}
int x = 0;
}
}
}
}