[英]How to define a PrimaryKeyPair for the database in C# (MVC)
I´m working with MVC3 in ASP .NET and stuck a little at the databasemodel.我正在使用 ASP .NET 中的 MVC3 并在数据库模型上停留了一点。
I use the EntityFramework to create tables from my models.我使用 EntityFramework 从我的模型创建表。 Now I want to define a PrimaryKey that depends from the MaterialID and the ListID.
现在我想定义一个依赖于 MaterialID 和 ListID 的 PrimaryKey。 But how can I define it in C#?
但是如何在 C# 中定义它?
Is there a Tag like [Key] to define that the PrimaryKey depends on more than one value?是否有像 [Key] 这样的标签来定义 PrimaryKey 依赖于多个值?
If you're using Entity Framework 4, you can specify a composite key in the constructor of your entity configuration like so:如果您使用的是 Entity Framework 4,则可以在实体配置的构造函数中指定复合键,如下所示:
HasKey(m => { m.MaterialID, m.ListID });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.