Last active
December 11, 2018 12:15
-
-
Save daisukenishino2/90b303d3bf0e5e4500e0d6d1d897d8d6 to your computer and use it in GitHub Desktop.
Open棟梁:POCOフィッティングのサンプル・プログラム https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Samples/WebApp_sample/MVC_Sample/MVC_Sample/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 一部、DataToDictionaryのテストコード | |
// https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Dto/DataToDictionary.cs | |
DataToDictionary d2d = null; | |
List<Dictionary<string, string>> list = null; | |
// マップなし | |
d2d = new DataToDictionary(null, null, null); | |
list = d2d.DataTableToDictionaryList(dt); | |
// マップあり | |
// Dictionary の Key-Value で src-dst のキー名を書く | |
d2d = new DataToDictionary( | |
new Dictionary<string, string>() | |
{ | |
{ "ShipperID", "_ShipperID"}, | |
{ "CompanyName", "_CompanyName"}, | |
{ "Phone", "_Phone"} | |
}, | |
null, null); | |
list = d2d.DataTableToDictionaryList(dt); | |
ret = new { Message = "", Result = list }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 共通Daoを生成 | |
CmnDao cmnDao = new CmnDao(this.GetDam()); | |
// 静的SQLを指定 | |
cmnDao.SQLText = "SELECT * FROM Shippers"; | |
// 共通Daoを実行 | |
IDataReader idr = cmnDao.ExecSelect_DR(); | |
// DataReaderToList | |
// https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Dto/DataToPoco.cs | |
List<ShipperViweModel> list = DataToPoco.DataReaderToList<ShipperViweModel>(idr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 共通Daoを生成 | |
CmnDao cmnDao = new CmnDao(this.GetDam()); | |
// 静的SQLを指定 | |
cmnDao.SQLFileName = "ShipperSelect.sql"; | |
// 1件参照のため、主キー値を設定 | |
cmnDao.SetParameter("P1", 1); | |
// 共通Daoを実行 | |
IDataReader idr = cmnDao.ExecSelect_DR(); | |
// DataTableToPOCO | |
// https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Dto/DataToPoco.cs | |
ShipperViweModel svm = DataToPoco.DataReaderToPOCO<ShipperViweModel>(idr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 共通Daoを生成 | |
CmnDao cmnDao = new CmnDao(this.GetDam()); | |
// 静的SQLを指定 | |
cmnDao.SQLText = "SELECT * FROM Shippers"; | |
// 戻り値 dt | |
DataTable dt = new DataTable(); | |
// 共通Daoを実行 | |
cmnDao.ExecSelectFill_DT(dt); | |
// DataTableToList | |
// https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Dto/DataToPoco.cs | |
List<ShipperViweModel> list = DataToPoco.DataTableToList<ShipperViweModel>(dt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 共通Daoを生成 | |
CmnDao cmnDao = new CmnDao(this.GetDam()); | |
// 静的SQLを指定 | |
cmnDao.SQLFileName = "ShipperSelect.sql"; | |
// 1件参照のため、主キー値を設定 | |
cmnDao.SetParameter("P1", 1); | |
// 戻り値 dt | |
DataTable dt = new DataTable(); | |
// 共通Daoを実行 | |
cmnDao.ExecSelectFill_DT(dt); | |
// DataTableToPOCO | |
// https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Dto/DataToPoco.cs | |
ShipperViweModel svm = DataToPoco.DataTableToPOCO<ShipperViweModel>(dt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 共通Daoを生成 | |
CmnDao cmnDao = new CmnDao(this.GetDam()); | |
// 静的SQLを指定 | |
cmnDao.SQLFileName = "ShipperSelect.sql"; | |
// 1件参照のため、主キー値を設定 | |
cmnDao.SetParameter("P1", 1); | |
// 戻り値 dt | |
DataTable dt = new DataTable(); | |
// 共通Daoを実行 | |
cmnDao.ExecSelectFill_DT(dt); | |
// DataTableToPOCO | |
// https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Dto/DataToPoco.cs | |
TestShipperViweModel tsvm = DataToPoco.DataTableToPOCO<TestShipperViweModel>(dt, | |
// mapの書き方は、Key-Valueでdst-srcのproperty field名を書く | |
new Dictionary<string, string>() | |
{ | |
{ "_ShipperID", "ShipperID"}, | |
{ "_CompanyName", "CompanyName"}, | |
{ "_Phone", "Phone"} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ShipperViweModel svm = new ShipperViweModel(); | |
TestShipperViweModel tsvm = TestShipperViweModel() | |
{ | |
_ShipperID = "_ShipperID", | |
_CompanyName = "_CompanyName", | |
_Phone = "_Phone", | |
... | |
}; | |
// https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Dto/PocoToPoco.cs#L81 | |
// src: TestShipperViweModel, dst: ShipperViweModel | |
PocoToPoco.Map<TestShipperViweModel, ShipperViweModel>( | |
tsvm, svm, | |
// PocoToPoco.Map の mapの書き方は、 | |
// Dictionary の Key-Value で dst-src のproperty field名を書く | |
new Dictionary<string, string>() | |
{ | |
{ "ShipperID", "_ShipperID"}, | |
{ "CompanyName", "_CompanyName"}, | |
{ "Phone", "_Phone"} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ShipperViweModel svm = new ShipperViweModel() | |
{ | |
_ShipperID = "_ShipperID", | |
_CompanyName = "_CompanyName", | |
_Phone = "_Phone", | |
... | |
}; | |
TestShipperViweModel tsvm = null; | |
// https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Dto/PocoToPoco.cs#L81 | |
// src: ShipperViweModel, dst: TestShipperViweModel | |
tsvm = PocoToPoco.Map<ShipperViweModel, TestShipperViweModel>( | |
svm, null, | |
// dstがnullの場合、戻り値から生成されたobjectを入手できる。 | |
new Dictionary<string, string>() | |
{ | |
{ "_ShipperID", "ShipperID"}, | |
{ "_CompanyName", "CompanyName"}, | |
{ "_Phone", "Phone"} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class POCO_FL | |
{ | |
public string aaa = ""; | |
public string bbb = ""; | |
public string xxx { set; get; } = ""; | |
public string yyy { set; get; } = ""; | |
} | |
public class POCO_FU | |
{ | |
public string AAA = ""; | |
public string BBB = ""; | |
public string XXX { set; get; } = ""; | |
public string YYY { set; get; } = ""; | |
} | |
public class POCO_ML | |
{ | |
public string aaa = ""; | |
public string bbb = ""; | |
public string ccc = ""; | |
public string xxx { set; get; } = ""; | |
public string yyy { set; get; } = ""; | |
public string zzz { set; get; } = ""; | |
} | |
public class POCO_MU | |
{ | |
public string AAA = ""; | |
public string BBB = ""; | |
public string CCC = ""; | |
public string XXX { set; get; } = ""; | |
public string YYY { set; get; } = ""; | |
public string ZZZ { set; get; } = ""; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
POCO_MU pmu = null; | |
POCO_FU pfu = null; | |
POCO_ML pml = null; | |
POCO_FL pfl = null; | |
#region POCO_MU -> POCO_FU | |
pmu = new POCO_MU() | |
{ | |
AAA = "AAA1", | |
BBB = "BBB1", | |
CCC = "CCC1", | |
XXX = "XXX1", | |
YYY = "YYY1", | |
ZZZ = "ZZZ1" | |
}; | |
pfu = PocoToPoco.Map<POCO_MU, POCO_FU>(pmu); | |
WriteLine.OutPutDebugAndConsole(ObjectInspector.Inspect(pfu)); | |
#endregion | |
#region POCO_FU -> POCO_MU | |
pfu = new POCO_FU() | |
{ | |
AAA = "AAA2", | |
BBB = "BBB2", | |
XXX = "XXX2", | |
YYY = "YYY2" | |
}; | |
pmu = PocoToPoco.Map<POCO_FU, POCO_MU>(pfu); | |
WriteLine.OutPutDebugAndConsole(ObjectInspector.Inspect(pmu)); | |
#endregion | |
#region POCO_MU -> POCO_FL | |
pmu = new POCO_MU() | |
{ | |
AAA = "AAA3", | |
BBB = "BBB3", | |
CCC = "CCC3", | |
XXX = "XXX3", | |
YYY = "YYY3", | |
ZZZ = "ZZZ3" | |
}; | |
pfl = PocoToPoco.Map<POCO_MU, POCO_FL>(pmu, new Dictionary<string, string>() | |
{ | |
{ "aaa", "AAA" }, | |
{ "bbb", "BBB" }, | |
{ "xxx", "XXX" }, | |
{ "yyy", "YYY" } | |
}); | |
WriteLine.OutPutDebugAndConsole(ObjectInspector.Inspect(pfl)); | |
#endregion | |
#region POCO_FU -> POCO_ML | |
pfu = new POCO_FU() | |
{ | |
AAA = "AAA4", | |
BBB = "BBB4", | |
XXX = "XXX4", | |
YYY = "YYY4" | |
}; | |
pml = PocoToPoco.Map<POCO_FU, POCO_ML>(pfu, new Dictionary<string, string>() | |
{ | |
{ "aaa", "AAA" }, | |
{ "bbb", "BBB" }, | |
{ "xxx", "XXX" }, | |
{ "yyy", "YYY" } | |
}); | |
WriteLine.OutPutDebugAndConsole(ObjectInspector.Inspect(pml)); | |
#endregion | |
Console.ReadKey(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
利用方法
サンプル
C#
MVC_Sample
ASPNETWebService
VB
インストール
v 2.3.0 以降で利用可能。
もしくは、
名前空間
Touryo.Infrastructure.Public.Dto
必要に応じて、using, Importsする。