我無法理解一件事。假設我已經有這些編碼實體:關於LINQ to SQL的簡單問題
[Table(Name = "Rates")]
public class Rate
{
private EntityRef<Product> _Product;
[Column(IsPrimaryKey = true)]
public String RateID
{ get; set; }
[Column]
public String ProductID
{ get; set; }
[Column]
public Double VolumeInTons
{ get; set; }
[Column]
public Decimal Volume
{ get; set; }
[Column]
public Decimal Cost
{ get; set; }
[Column]
public UInt32 Year
{ get; set; }
[Association(Storage = "_Product", OtherKey = "ProductID")]
public Product Product
{
get { return this._Product.Entity; }
set { this._Product.Entity = value; }
}
}
而且
[Table(Name="Products")]
public class Product
{
private EntitySet<Rate> _Rates;
[Column(IsPrimaryKey= true)]
public String ProductID
{ get; set; }
[Column]
public String Name
{ get; set; }
[Column]
public String Category
{ get; set; }
[Association(Storage="_Rates", OtherKey="ProductID")]
public EntitySet<Rate> Rates
{
get { return this._Rates; }
set { this._Rates.Assign(value); }
}
}
- 我應該有一個物理數據庫具有相同表定義連接(在我的應用程序中使用的DataContext)?
- 假設我已經創建了一個數據庫。它應該包含相同的表定義還是
LINQ to SQL
創建它們?
看看[這個](http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.createdatabase.aspx)方法 – Reniuz 2011-05-28 06:31:53