有关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
创建它们?     
已邀请:
        如果您已有数据库,则可以从Visual Studio连接到数据库,然后将表拖放到“ 3”的设计模式中。然后,Visual Studio将为您生成相应的类。 另外,可能的答案是,您已经具有生成的类(例如:来自具有数据库的其他系统),并且您想根据类定义创建数据库。然后,您应该在代码的早期位置调用一次DataContext.CreateDatabase(同样由Reniuz指出),然后将创建数据库。请注意,在下次运行时,您无需再次创建数据库。     

要回复问题请先登录注册