如何设置名称为"多场"主键(约束主键)在实体框架? [英] how to set NAME for "multi fields" primary keys (Constraint Primary Key) in entity framework?
问题描述
如何为多田主键(约束主键)在实体框架的名字?
例如:
How to set name for "multi fields" primary keys (Constraint Primary Key) in entity framework?? for example :
// CONSTRAINT PKRoles PRIMARY KEY (Rolename, ApplicationName)
我可以实现code的一部分:
i can implement only part of the code :
SQL COD:
sql cod:
CREATE TABLE Roles
(
Rolename Text (255) NOT NULL,
ApplicationName Text (255) NOT NULL,
CONSTRAINT PKRoles PRIMARY KEY (Rolename, ApplicationName)
)
实施(转换为实体):
public class Roles
{
[Key, Column(Order = 0)]
public string Rolename { get; set; } //(255) NOT NULL
[Key, Column(Order = 1)]
public string ApplicationName { get; set; } //(255) NOT NULL
//CONSTRAINT PKRoles PRIMARY KEY (Rolename, ApplicationName)
}
我看到数据库的密钥部分,即创建的 PK_dbo.Roles 的名关键!
但我需要创建密钥的 PKRoles 的NEME!
i see in keys section of database , that create key with "PK_dbo.Roles" name ! but i need create key "PKRoles " neme!
请帮我实现上面code端线。结果
非常感谢。
please help me to implement end line above code.
thanks a lot.
推荐答案
请问code低于你想要什么?
Does the code below do what you want?
public class Roles
{
[Key, Column("PKRoles", Order = 0)]
public string Rolename { get; set; } //(255) NOT NULL
[Key, Column("PKRoles", Order = 1)]
public string ApplicationName { get; set; } //(255) NOT NULL
}
您正在查找的词是复合键,您也许能使用流利的API。这可能会帮助你的搜索,如果这是行不通的。
The word you are looking for is "composite key" and you might be able to use the fluent API. That might help your search if this does not work.
这篇关于如何设置名称为"多场"主键(约束主键)在实体框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!