首先创建数据库连接,代码如下:
public class DapperFactory { public static readonly string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Wip_TestConnStr"].ToString(); public static OracleConnection CrateOracleConnection() { var connection = new OracleConnection(connectionString); connection.Open(); return connection; } }
其次,基于Oracle,实现简单的增、删、改、查、事务、分页等。
using System; using System.Data; using System.Collections; using System.Xml; using System.Runtime.Serialization; namespace Tcl.ForLog.Model { /// <summary> /// 表WUFEI_TESTTB的对象类 /// </summary> [DataContract(Name = "WUFEI_TESTTB")] public class WUFEI_TESTTBModel { #region 表名称常量 /// <summary> /// 表名称 /// </summary> public const string TABLE_NAME = "WUFEI_TESTTB"; #endregion #region 属性 /// <summary> /// 用户ID /// </summary> [DataMember(Name = "USER_ID")] public decimal USER_ID { get; set; } /// <summary> /// 用户名称 /// </summary> [DataMember(Name = "USER_NAME")] public string USER_NAME { get; set; } /// <summary> /// 用户地址 /// </summary> [DataMember(Name = "USER_ADDRESS")] public string USER_ADDRESS { get; set; } /// <summary> /// 用户性别 /// </summary> [DataMember(Name = "USER_SEX")] public string USER_SEX { get; set; } /// <summary> /// 用户生日 /// </summary> [DataMember(Name = "USER_BIRTHDAY")] public DateTime USER_BIRTHDAY { get; set; } /// <summary> /// 备注 /// </summary> [DataMember(Name = "USER_REMARK")] public string USER_REMARK { get; set; } /// <summary> /// WUFEI_TESTTBModel深拷贝 /// </summary> /// <returns></returns> public static WUFEI_TESTTBModel DeepCopy(WUFEI_TESTTBModel testTbA) { WUFEI_TESTTBModel testTbB = new WUFEI_TESTTBModel(); testTbB.USER_ID = testTbA.USER_ID; testTbB.USER_NAME = testTbA.USER_NAME; testTbB.USER_ADDRESS = testTbA.USER_ADDRESS; testTbB.USER_SEX = testTbA.USER_SEX; testTbB.USER_BIRTHDAY = testTbA.USER_BIRTHDAY; testTbB.USER_REMARK = testTbA.USER_REMARK; return testTbB; } #endregion } }