Here is an example for the Resource class in ProjectTracker application (generated by Code Complete)
//ReadOnlyListBase
namespace
ProjectTrackerDemoWin{
[
Serializable()] public partial class BLResourceInfoList : ReadOnlyListBase<BLResourceInfoList, BLResourceInfo>{
#region
"Factory Methods" public static BLResourceInfoList GetBLResourceInfoList(System.String LastName){
return DataPortal.Fetch<BLResourceInfoList>(
new FilteredCriteria(LastName));}
private BLResourceInfoList(){
} #endregion#region
"Data Access"[
Serializable()] private class FilteredCriteria{
private System.String _LastName = string.Empty;public System.String LastName
{
get{
return _LastName;}
}
public FilteredCriteria(System.String LastName){
_LastName = LastName;
}
}
private void DataPortal_Fetch(FilteredCriteria criteria){
Fetch(criteria.LastName);
}
//Search by last name using LIKE type operatorpublic void Fetch(System.String LastName)
{
try
{
RaiseListChangedEvents =
false; using (var ctx = ContextManager<ProjectTrackerSQLDataContext>.GetManager("ProjectTrackerSQL")){
IEnumerable<Resource> Resources = (from record in ctx.DataContext.Resources where record.LastName.StartsWith(LastName) select record);IsReadOnly =
false; foreach (Resource item in Resources){
BLResourceInfo info = new BLResourceInfo(item.Id,item.LastName,
item.FirstName);
this.Add(info);}
IsReadOnly =
true;}
RaiseListChangedEvents =
true;}
catch (Exception ex){
throw ex;}
}
#endregion}
}
//ReadOnlyClass
namespace
ProjectTrackerDemoWin{
[
Serializable()] public partial class BLResourceInfo : ReadOnlyBase<BLResourceInfo>{
#region
"Private Variables" private System.Int32 _Id; private System.String _LastName = string.Empty;private System.String _FirstName = string.Empty;
#endregion
#region
"Public Properties" public System.Int32 Id{
get{
return _Id;}
}
public System.String LastName{
get{
return _LastName;}
}
public System.String FirstName{
get{
return _FirstName;}
}
protected override object GetIdValue(){
return _Id;}
#endregion
#region
"Constructors" private BLResourceInfo(){ }
internal BLResourceInfo(System.Int32 Id,System.
String LastName,System.
String FirstName){
_Id = Id;
_LastName = LastName;
_FirstName = FirstName;
}
#endregion
}
}
Philip
Copyright (c) Marimer LLC