假设我在数据库中有一张表格,由以下列组成,其中3列唯一标识行:
我们的团队正在进行一场辩论,因为我们中有些人认为,在集合中引用一行时使用其内部索引更有意义,而其他人则认为没有必要引入另一个内部键,因为我们已经可以根据三个属性唯一地识别一行。
你怎么想?
CREATE TABLE [dbo].[Lines]
(
[Attr1] [nvarchar](10) NOT NULL,
[Attr2] [nvarchar](10) NOT NULL,
[Attr3] [nvarchar](10) NOT NULL,
PRIMARY KEY (Attr1, Attr2, Attr3)
)
现在,我的应用程序中有一个对象代表其中一行。它有三个属性,分别对应数据库中的三个Attr列。
public class Line
{
public Line(string attr1, string attr2, string attr3)
{
this.Attr1 = attr1;
this.Attr2 = attr2;
this.Attr3 = attr3;
}
public Attr1 {get; private set;}
public Attr2 {get; private set;}
public Attr3 {get; private set;}
}
该应用程序中还有第二个对象,存储了这些线条对象的集合。
问题是:当引用此集合中的单个线条时(从调用者的角度),最适合的设计是什么?调用者是否应负责跟踪正在更改的线的索引,然后只使用该索引直接修改集合中的线?或者......对象上是否应该有一些方法,以类似以下方式发出命令:
public GetLine(string attr1, string attr2, string attr3)
{
// return the line from the collection
}
public UpdateLine(Line line)
{
// update the line in the collection
}
我们的团队正在进行一场辩论,因为我们中有些人认为,在集合中引用一行时使用其内部索引更有意义,而其他人则认为没有必要引入另一个内部键,因为我们已经可以根据三个属性唯一地识别一行。
你怎么想?