我需要专家的意见。我编写自己的SQL Helper类来与DB通信。
为什么我使用它,因为我试图
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
#region include SQL Helper Namespace
using DBManager;
#endregion
#region include SQL Helper Namespace
using DBManager;
#endregion
namespace ContentManagementSystem.DataAccessLayer
{
/// <summary>
///
/// </summary>
public sealed class DaoContentOwner : DataAccessBase
{
#region CONSTRUCTOR
/// <summary>
///
/// </summary>
private DaoContentOwner()
{
GetInstance = new DaoContentOwner();
}
#endregion
//############################################# M E T H O D S ##########################
#region Retrieve Content Owner
/// <summary>
/// Retrieve Content Owner
/// </summary>
/// <returns></returns>
public static DataTable RetrieveContentOwner()
{
DataTable dt = null;
try
{
using (DBQuery dq = new DBQuery("stpGetContentOwner"))
{
dt = dq.ResultSetAsDataTable();
return dt;
}
}
catch (Exception)
{
throw;
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
}
#endregion
//############################################# P R O P E R T Y ########################
#region READ ONLY PROPERTY
/// <summary>
/// GetInstance of DaoContentOwner Class
/// </summary>
public static DaoContentOwner GetInstance { get; private set; }
#endregion
}
}
理由:
“ DataAccessBase ”这是一个抽象类。实现IDisposable接口。
对于仅限SQL Server ,“ DBQuery ”是 SQL Helper 。这是一个密封课程。根据需要需要T-SQL / SP。打开关闭数据库连接。没有必要由开发人员处理任何事情。
为什么我要制作DAO Singleton类,因为我使用DAO的所有方法都是静态方法。我命令内存优化我使它成为Singleton。它也是设计负责人。
注意:需要评论。是否需要改变设计或某些事情是错误的,需要纠正。
答案 0 :(得分:0)
就个人而言,我会选择:
DALFileItem dalF = new DALFileItem(DSN);
List<FileItem> list = dalF.GetAll("");