HI All!
(I initially posted this as a comment to another thread in the "General" forum... but I think this is better suited for the "Getting Started" forum here as a new thread so I am adding my question here as well).
I am looking for a little guidance... what is Telerik's recommendation on extending the object class, i.e. creating additional constructors, properties, public static functions for my business objects?
I typically like to create:
1) a constructor that will initialize my business object class using its unique ID,
2) create additional private variables with associated public properites, and
3) also would like to create some reusable business logic common functions for each business object.
For example, let's say I have a data table called DATPage and use Reverse Mapping feature to generate the DATPage.cs file. I have included code sample below (stripped down version) to use as a reference.
DATPage.cs - Open Access Reverse Mapping (automatic generated file "customized")
namespace DataMine.DataAccess | |
{ | |
public partial class DATPage | |
{ | |
// Private local variables. | |
private _IsTopPage bool; | |
public DATPage() { } | |
#region "Additional Constructors" | |
public DATPage(int page_id) | |
{ | |
this.LoadByPrimaryKey(page_id); | |
SetDefaults(page_id); | |
} | |
private void SetDefaults(int page_id) | |
{ | |
this.NavigateUrl= this.NavigateUrl + "?pg=" + page_id; | |
_IsTopPage = IsTopPage(); | |
} | |
#endregion | |
#region "Additional Public Properties" | |
public int IsTopPage | |
{ | |
get { return _IsTopPage; } | |
set { _IsTopPage= value; } | |
} | |
#endregion | |
#region "Public Static Functions" | |
public static DATPage GetPageByID(int page_id) | |
{ | |
string query = "SELECT * FROM DATPageExtent as c WHERE page_id=" + page_id; | |
IQueryResult result = ObjectScopeProvider1.GetNewObjectScope().GetOqlQuery(query).Execute(); | |
return (DATPage)result; | |
} | |
public static List<DATPage> GetChildPageObjects(int parent_id) | |
{ | |
string query = "SELECT * FROM DATPageExtent as c WHERE parent_id=" + parent_id; | |
IQueryResult result = ObjectScopeProvider1.GetNewObjectScope().GetOqlQuery(query).Execute(); | |
return (List<DATPage>)result; | |
} | |
} | |
#endregion | |
Questions (best practice):
- Is it recommended that I put the additional constructors in the DATPage.cs file that was generated by OA Reverse Engineering (as I have done here in my sample)?
- Can you provide sample code that would demonstrate how I might implement the "LoadByPrimaryKey()" method (line 14). I am looking for a method that would populate my business object, (like a Fill() method on a datatable adapter). Does a method exist in OpenAccess for this or is there alternate method you would recommend?
- I would like to store reusable "public static functions" that will return business objects, Generic Lists, DataTables etc... (for example line 36, 44). Would you recommend that I store these functions in the generated DATPage.cs file as well or create a separate class for these, like in a file called DATPageCollection.cs perhaps?
Any help and advice would be greatly appreciated.
Thanks,
Tad