I am using .NET 2.0. I have 2 objects one is: PhoneService and the other one is ChartOfAccount. The relationship between this to is many to many.
public class PhoneService
{
private List<ChartAccount> chartAccounts
private ChartAccount chartAccount
public Int64 ID
{
get { return id; }
set { id = value; }
}
public bool Add()
{ ... }
public bool Update()
{ ... }
}
public class ChartAccount
{
public Int64 ID
{
get { return id; }
set { id = value; }
}
public bool Add()
{ ... }
public bool Update()
{ ... }
public bool Allocate()
{
// this will save data for the bridge table only
}
}
Now my question, is it possible when you do this:
PhoneService service = new PhoneService();
service.ChartAccounts[0].ID = 5
service.ChartAccounts[1].ID = 10
Due to ChartAccounts is a collection, how do I attemp to put Allocate() so become like:
service.ChartAccounts.Allocate()
All I can think of is putting the Allocate() method in Service class instead. Any ideas?
Thanks
While this may not be the cleanest way , you could always just create a ChartAccounts class that only contains a list of chartaccounts and add the method to that class. The other option is to create a extension method on the chatAccount class to perform the allocate code.