例如考虑http://starcounter.io/tutorials/1-introduction-to-part-1/ InvoiceDemo上的示例应用程序
声明了以下数据库对象
using Starcounter;
[Database]
public class Invoice {
public int InvoiceNo;
public string Name;
public decimal Total {
get {
return Db.SQL<decimal>(@"SELECT sum(r.Total)
FROM InvoiceRow r
WHERE r.Invoice = ?",
this).First;
}
}
public QueryResultRows<InvoiceRow> Items {
get {
return Db.SQL<InvoiceRow>(@"SELECT r
FROM InvoiceRow r
WHERE r.Invoice = ?",
this);
}
}
public Invoice() {
new InvoiceRow() {
Invoice = this
};
}
}
[Database]
public class InvoiceRow {
public Invoice Invoice;
public string Description;
public int Quantity;
public decimal Price;
public decimal Total {
get {
return Quantity * Price;
}
}
public InvoiceRow() {
Quantity = 1;
}
}
如果我想确保我知道已添加的发票行的顺序,我会在标准 SQL 数据库中只使用自动增量 ID。Starcounter的最佳实践是什么?