forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (59 loc) · 2.44 KB
/
Program.cs
File metadata and controls
71 lines (59 loc) · 2.44 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
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
69
70
71
using System;
using System.Data.Entity;
using System.Linq;
using System.Linq.Dynamic.Core;
namespace ConsoleApp.EntityFrameworkClassic
{
internal class Program
{
public static string ConnectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=EFClassic;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
public static void Main()
{
// CLEAR
using (var context = new EntityContext())
{
context.Customers.RemoveRange(context.Customers);
context.SaveChanges();
Console.WriteLine("Database clearer...");
}
// ADD 2 new customers
using (var context = new EntityContext())
{
context.Customers.Add(new Customer { Name = "Customer_A", Description = "Description", IsActive = true });
context.Customers.Add(new Customer { Name = "Customer_B", Description = "Description", IsActive = true });
context.SaveChanges();
Console.WriteLine("Customers added...");
}
using (var context = new EntityContext())
{
foreach (var customer in context.Customers.AsQueryable().Where("it != null && CustomerID >= 1000").ToList())
{
Console.WriteLine("");
Console.WriteLine("Customer.CustomerID : " + customer.CustomerID);
Console.WriteLine("Customer.Name : " + customer.Name);
Console.WriteLine("Customer.Description : " + customer.Description);
Console.WriteLine("Customer.IsActive : " + customer.IsActive);
}
Console.WriteLine("");
Console.WriteLine("---");
Console.WriteLine("");
}
Console.WriteLine("Press any key.");
Console.ReadKey();
}
public class EntityContext : DbContext
{
public EntityContext() : base(ConnectionString)
{
}
public DbSet<Customer> Customers { get; set; }
}
public class Customer
{
public int CustomerID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
}
}
}