I currently have a class similar to the below (omited error checking)
Currently this is how the database is wrapped into easier to use objects.
I was wondering if I was going to be loading say 50,000 orders if I should be creating the table adapters once and then reusing them, instead of creating a new table adapter for each order?
I have not seen any real speed issues doing it this way. But would it be best practise to not keep creating new table adapters each time?
If so is there a pre-existing patten to handle this?
class Order
{
public int Id {get; private set;}
public string CustomerEmail { get; set; }
public SaleLocaion SalePoint { get; set; }
public Order(int orderId)
{
using (var ta = new OrdersTableAdapter())
{
using (var res = ta.GetDataById(orderId))
{
if (res.Count == 1)
{
var row = res.First();
Id = row.Id;
CustomerEmail = row.Email;
SalePoint = new SaleLocaion(row.SaleLocationId);
}
}
}
}
}
class SaleLocaion
{
public int Id {get; private set;}
public string Name { get; private set; }
public SaleLocaion(int locationId)
{
using (var ta = new SaleLocationAdapter())
{
using (var res = ta.GetDataById(locationId))
{
if (res.Count == 1)
{
var row = res.First();
Id = row.Id;
Name = row.Name;
}
}
}
}
}