-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (45 loc) · 1.49 KB
/
Program.cs
File metadata and controls
60 lines (45 loc) · 1.49 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
// See https://aka.ms/new-console-template for more information
using Microsoft.Data.SqlClient;
using System.Data.Common;
using QueryProviderExample;
using System.Linq.Expressions;
const string connectionString = "Server=localhost;Database=Northwind;User=sa;Password=Dracarys3;TrustServerCertificate=True";
using var sqlConnection = new SqlConnection(connectionString);
sqlConnection.Open();
var db = new Northwind(sqlConnection);
var city = "London";
var query = db.Customers.Where(c => c.City == city)
.Select( x => new { Name = x.ContactName, Phone = x.Phone});
Console.WriteLine(query.Expression.ToString());
foreach (var customer in query.ToList())
{
Console.WriteLine($"{customer.Name} - {customer.Phone}");
}
sqlConnection.Close();
var a = () => 1;
var b = a();
public class Customers
{
public string CustomerID { get; set; }
public string ContactName { get; set; }
public string Phone { get; set; }
public string City { get; set; }
public string Country { get; set; }
}
public class Orders
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
public DateTime OrderDate { get; set; }
}
public class Northwind
{
public MyQueryable<Orders> Orders;
public MyQueryable<Customers> Customers;
public Northwind(DbConnection connection)
{
DbQueryProvider provider = new DbQueryProvider(connection);
Customers = new MyQueryable<Customers>(provider);
Orders = new MyQueryable<Orders>(provider);
}
}