I used myGeneration in some projects; I noticed that BusinessEntity keeps the result of the query in a DataTable, But what if the developer wants to get the result as List of objects? To solve this, I made the following modification for my own use.
public class BusinessEntity
{
//....
public DataTable TheDataTable
{
get
{
return _dataTable;
}
set
{
_dataTable = value;
}
}
public void PutTheRow(DataRow pRow)
{
DataRow newRow = _dataTable.NewRow();
newRow.ItemArray = pRow.ItemArray;
_dataTable.Rows.Add(newRow);
_dataRow = newRow;
//Rewind();
_dataTable.AcceptChanges();
}
.......
}
Now suppose we have a table "Employee" and we generate a class for him, also I make the following modification:
public abstract class Employee : _Employee
{
public Employee()
{
}
public List<Employee> AsList()
{
List<Employee> list = new List<Employee>();
Employee businessEntity = null;
foreach (System.Data.DataRow row in TheDataTable.Rows)
{
businessEntity = new Employee();
businessEntity.TheDataTable = TheDataTable.Clone();
businessEntity.PutTheRow(row);
list.Add(businessEntity);
}
return list;
}
}
Now I can Get a list of objects, from the result of the query, instead of one object and the result in the data table :
Employee employee = new Employee();
employee.Where.ID.Operator = WhereParameter.Operand.NotIn;
employee.Where.ID.Value = "1,2,3";
employee.Query.Load();
foreach (Employee employeeLoop in employee.AsList())
{
TreeNode node = new TreeNode(employeeLoop.s_ID);
node.Tag = employeeLoop;
mMainTree.Nodes.Add(node);
}
Then I can access the selected Employee as following:
Employee emp = (Employee) mMainTree.SelectedNode.Tag;
emp.Name = "WWWWW";
emp.Save();
thanks. Do You have a better tips, Ideas? for more discussion, please visit MyGeneration forum.