我创建了对象类列表并从CreateListFromTable方法返回。但总是虚拟方法正在调用并抛出异常。数据未加载到列表中。对象列表无法正确加载?
可能是什么问题?
public static List<Customer> GetCustomer(string ID)
{
DataTable dt = new DataTable();
try
{
DatabaseGateway da = new DatabaseGateway();
dt = da.QueryForDataTable("proc_GetCustomer", ID);
}
catch (Exception ex)
{
LogMessage(ex.Message + ": " + ex.StackTrace, EventLogEntryType.Error);
}
return CreateListFromTable<Customer>(dt);
}
protected static List<T> CreateListFromTable<T>(DataTable dt) where T : BusinessObject, new()
{
List<T> list = new List<T>();
try
{
if (dt != null)
foreach (DataRow row in dt.Rows)
{
T t = new T();
t.Load(row);
list.Add(t);
}
}
catch (Exception exception)
{
}
return list;
}
/// <summary>
/// Virtual method which should be overriden by inherited types that support loading.
/// </summary>
/// <param name="row"></param>
protected virtual void Load(DataRow row)
{
throw new NotSupportedException("The object of type '" + this.GetType().Name +
"' does not support loading from DataRow.");
}
什么可能是例外? – GazTheDestroyer
{“'Customer'类型的对象不支持从DataRow加载。”} – James123