C# EasyORM
申明:本作品采用知識共享署名-非商業性使用-相同方式共享 2.5 中國大陸許可協議進行許可,我的博客歡迎復制共享,但在同時,希望保留我的署名權CHARSET,并且,不得用于商業用途。如您有任何疑問或者授權方面的協商,請聯系我。
使用反射和配置來實現SQL->.NET類的映射
1 SELECT Field1,Field2,Field3 FROM table_name WHERE Field4=?
上述例子是由于OleDb不支持命名參數,以下均為OleDb作為例子。
配置如下:
1 <Statement> 2 <SQL><!CDATA[[SELECT Field1,Field2,Field3 FROM table_name WHERE Field4=?]]></SQL> 3 <Parameters> 4 <Parameter Name="@Field4" Type="System.String" /> 5 </Parameters> 6 <Result ReturnList="False/True" Type="Query.Information.ClientInfo,Query.Information.ClientInfo"> 7 <Field Name="Field1" Mapping="Dummy" Type="System.Decimal" /> 8 <Field Name="Field2" Mapping="Name" Type="System.String" /> 9 <Field Name="Field3" Mapping="Salary" Type="System.Double" /> 10 </Result> 11 </Statement>
類定義是:
1 public classClientInfo{ 2 [Entity]public decimal Dummy{ get; set; } 3 [Entity]public string Name{get;set; } 4 [Entity]public double Salary{get;set; } 5 }
使用下面函數來獲得類的示例:
1 object SQLHelper.Execute(XXXConnection connection, string profile, Dictionary<string, string> KV);
方法如下:
1 Dictionary<string,string> KV = new Dictionary<string,string>(); 2 KV.Add("@Field4", "SID0001"); 3 Query.Information.ClientInfo clientInfo 4 = SQLHelper.Execute(connection, "獲得產品信息", KV) as Query.Information.ClientInfo;
或者:
1 Dictionary<string,string> KV = newDictionary<string,string>(); 2 KV.Add("@Field4", "SID0001"); 3 List<Query.Information.ClientInfo>clientInfo 4 = SQLHelper.Execute(connection, "獲得產品信息", KV) as List<Query.Information.ClientInfo>;

浙公網安備 33010602011771號