【发布时间】:2010-12-07 06:36:58
【问题描述】:
我正在使用 .NET 2.0。我有 2 个对象,一个是:PhoneService,另一个是 ChartOfAccount。这之间的关系是多对多的。
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
}
}
现在我的问题是,当你这样做时是否可能:
PhoneService service = new PhoneService();
service.ChartAccounts[0].ID = 5
service.ChartAccounts[1].ID = 10
由于 ChartAccounts 是一个集合,我该如何尝试把 Allocate() 变成这样: service.ChartAccounts.Allocate()
我能想到的只是将 Allocate() 方法放在 Service 类中。有什么想法吗?
谢谢
【问题讨论】:
标签: .net