C#中Manager方法标准写法
public List<Brand> GetBrandsByManufacturerName(string manufacturerName)
{
var listBrand = new List<Brand>();
var cmdText = string.Format($"[GCP.Runtime].[Product.GetBrandsByManufacturer]");
string connectionString = GetDb(DBType.CoreRead);
using (SqlConnection connection = new SqlConnection(connectionString))
using (var cmd = new SqlCommand(cmdText, connection))
{
cmd.CommandType = CommandType.StoredProcedure;
#region
cmd.Parameters.Add(SqlDbType.NVarChar.In("Manufacturer", 50, manufacturerName));
cmd.Parameters.Add(SqlDbType.NChar.In("Columns", 2000, "*"));
#endregion
cmd.Connection.Open();
using (var reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
var listFields = GetAllFields(reader);
while (reader.Read())
{
Brand brand = ConvertModel_Runt(reader, listFields);
listBrand.Add(brand);
}
}
}
}
return listBrand;
}
/// <summary>
/// 根据DBType获取不同的数据库连接字符串
/// </summary>
/// <param name="dbType"></param>
/// <returns></returns>
protected string GetDb(DBType dbType)
{
var key = $"{dbType}DB";
var con = ConfigurationManager.ConnectionStrings[key];
return con.ConnectionString;
}