-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAbstract-Class-Implementation.linq
53 lines (40 loc) · 1.29 KB
/
Abstract-Class-Implementation.linq
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
<Query Kind="Program">
<NuGetReference>Insight.Database</NuGetReference>
<Namespace>Insight.Database</Namespace>
<Namespace>System.Data.SqlClient</Namespace>
</Query>
void Main()
{
var connection = new SqlConnection(MyExtensions.SQLConnectionString);
SqlInsightDbProvider.RegisterProvider();
var repo = connection.As<HelloRepo>();
repo.GetType().Dump();
var res1 = repo.GetParent();
res1.Dump();
var res2 = repo.GetParentChild();
res2.Dump();
}
public abstract class HelloRepo
{
public abstract IDbConnection GetConnection();
[Sql("SELECT 1 ParentId, 'Jaxel' Name, 'Rojas' SecondName")]
public abstract Parent GetParent();
public IEnumerable<Parent> GetParentChild() =>
GetConnection().Query(@"SELECT 1 ParentId, 'Jaxel' Name, 'Rojas' SecondName
SELECT 1 ParentId, 4 ChildId, 'Aidan' ChildName, 'Rojas' SecondChildName",
Parameters.Empty, Query.Returns<Parent>()
.ThenChildren(Some<Child>.Records), CommandType.Text);
}
public class Parent
{
public int ParentId { get; set; }
public string Name { get; set; }
public string SecondName { get; set; }
public IEnumerable<Child> Childs { get; set; }
}
public class Child
{
public int ChildId { get; set; }
public string ChildName { get; set; }
public string SecondChildName { get; set; }
}