lex*_*eme 2 c# database database-connection 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; }
}
}
Run Code Online (Sandbox Code Playgroud)
和
[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); }
}
}
Run Code Online (Sandbox Code Playgroud)
LINQ to SQL
创建它们?如果您已有数据库,则可以从Visual Studio连接到该数据库,然后将表拖放到您的设计模式中DataContext
.然后,Visual Studio将为您生成相应的类.
或者,您可能正在回答的问题是,您已经拥有生成的类(例如:来自与数据库不同的系统),并且您希望根据类定义创建数据库.然后,您应该在代码的早期某处调用一次DataContext.CreateDatabase(如Reniuz所述),并创建数据库.请注意,在下次运行时,您无需再次创建数据库.
归档时间: |
|
查看次数: |
76 次 |
最近记录: |