简体   繁体   中英

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.

I use the EntityFramework to create tables from my models. Now I want to define a PrimaryKey that depends from the MaterialID and the ListID. But how can I define it in C#?

Is there a Tag like [Key] to define that the PrimaryKey depends on more than one value?

数据库图

If you're using Entity Framework 4, you can specify a composite key in the constructor of your entity configuration like so:

HasKey(m => { m.MaterialID, m.ListID });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM