Skip to content

Commit 9d39236

Browse files
committed
there is some issues. i will look later.
1 parent a576aa4 commit 9d39236

File tree

6 files changed

+128
-0
lines changed

6 files changed

+128
-0
lines changed

InheritanceHierachyDapper.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31205.134
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InheritanceHierachyDapper", "src\InheritanceHierachyDapper\InheritanceHierachyDapper.csproj", "{7106CF29-1795-4B95-B38D-37C51EE2D950}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{7106CF29-1795-4B95-B38D-37C51EE2D950}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7106CF29-1795-4B95-B38D-37C51EE2D950}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7106CF29-1795-4B95-B38D-37C51EE2D950}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7106CF29-1795-4B95-B38D-37C51EE2D950}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {8534A993-6827-458F-B553-7D17C0C36486}
24+
EndGlobalSection
25+
EndGlobal
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace InheritanceHierachyDapper
8+
{
9+
public abstract class Contract
10+
{
11+
public int ContractId { get; set; }
12+
public DateTime StartDate { get; set; }
13+
public int DurationMonths { get; set; }
14+
public decimal Charge { get; set; }
15+
public ContractType ContractType { get; set; }
16+
public int CustomerId { get; set; }
17+
}
18+
public class MobileContract : Contract
19+
{
20+
public MobileContract() => ContractType = ContractType.Mobile;
21+
public string MobileNumber { get; set; }
22+
}
23+
public class TvContract : Contract
24+
{
25+
public TvContract() => ContractType = ContractType.TV;
26+
public TVPackageType TVPackageType { get; set; }
27+
}
28+
public class BroadBandContract : Contract
29+
{
30+
public BroadBandContract() => ContractType = ContractType.Broadband;
31+
public int DownloadSpeed { get; set; }
32+
}
33+
public enum TVPackageType
34+
{
35+
S, M, L, XL
36+
}
37+
public enum ContractType
38+
{
39+
Mobile = 1, TV, Broadband
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="3.1.20" />
10+
</ItemGroup>
11+
12+
</Project>
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Microsoft.Data.Sqlite;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace InheritanceHierachyDapper
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
var tvContracts = new List<TvContract>();
12+
var mobileContracts = new List<MobileContract>();
13+
var broadbandContracts = new List<BroadBandContract>();
14+
var sql = @"select * from contracts";
15+
using (var connection = new SqliteConnection("Data Source = Projects"))
16+
{
17+
using (var reader = connection.ExecuteReader(sql))
18+
{
19+
var tvContractParser = reader.GetRowParser<TvContract>();
20+
var mobileContractParser = reader.GetRowParser<MobileContract>();
21+
var broadbandContractParser = reader.GetRowParser<BroadBandContract>();
22+
23+
while (reader.Read())
24+
{
25+
var discriminator = (ContractType)reader.GetInt32(reader.GetOrdinal(nameof(ContractType)));
26+
switch (discriminator)
27+
{
28+
case ContractType.TV:
29+
tvContracts.Add(tvContractParser(reader));
30+
break;
31+
case ContractType.Broadband:
32+
broadbandContracts.Add(broadbandContractParser(reader));
33+
break;
34+
case ContractType.Mobile:
35+
mobileContracts.Add(mobileContractParser(reader));
36+
break;
37+
}
38+
}
39+
}
40+
41+
}
42+
Console.WriteLine("TV Contracts");
43+
tvContracts.ForEach(c => Console.WriteLine($"Duration: {c.DurationMonths} months, Package Type: {c.TVPackageType.ToString()}"));
44+
Console.WriteLine("Broadband Contracts");
45+
broadbandContracts.ForEach(c => Console.WriteLine($"Duration: {c.DurationMonths} months, Cost: {c.Charge}, Download: {c.DownloadSpeed} Mbps"));
46+
Console.WriteLine("Mobile Contracts");
47+
mobileContracts.ForEach(c => Console.WriteLine($"Duration: {c.DurationMonths} months, Number: {c.MobileNumber}"));
48+
}
49+
}
50+
}

src/ProjectDB.db

8 KB
Binary file not shown.

src/ProjectDB.db-journal

8.52 KB
Binary file not shown.

0 commit comments

Comments
 (0)