Hi,
I'm trying to create a NVL that can retrieve a full set or a filtered set of records. My thinking is to have two factory methods as in:
public
static MyList GetList(){
if (_list == null){
_list =
DataPortal.Fetch<MyList>(new Criteria(typeof(MyList)));}
return _list;
}
public static MyList GetList(Guid id)
{
if (_list == null)
{
_list = DataPortal.Fetch<MyList>(new Criteria(id));
}
return _list;
}
Then a dataportal_fetch as in:
private
void DataPortal_Fetch(Criteria criteria){
RaiseListChangedEvents =
false; using (SqlConnection cn = new SqlConnection(DatabaseConnection.MyDB)){
cn.Open();
using (SqlCommand cm = cn.CreateCommand()){
cm.CommandType =
CommandType.StoredProcedure;cm.CommandText =
"spGetMyList";cm.Parameters.AddWithValue(
"@prog_id", criteria.Id); using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())){
IsReadOnly =
false; while (dr.Read()){
Add(
new NameValuePair(dr.GetGuid("net_id"), dr.GetString("net_name")));}
IsReadOnly =
true;}
}
}
RaiseListChangedEvents =
true;}
I'm retrieving data from a parent-child table relationship. Sometimes I would like to have all children, the other times I would like to have children for a specific parent.
Should I use a single stored procedure or one for each list?. Should I have a second data_portal fetch?
Thanks
Regards
Thanks Andy,
I've added a second factory method with a parameter and added an override to the fetch method, everything works like a dream. The bug you've mentioned did appear. My application is somewhat unique so to combat that issue I call the public InvalidateCache method before loading the data.
Regards,
Copyright (c) Marimer LLC