DbMigration.AddPrimaryKey 方法 (String, String[], String, Boolean, Object)

[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 msdn.com/data/ef。]

添加基于多列创建新主键的操作。 实体框架迁移 API 未被设计为接受不可信源(例如应用程序的最终用户)提供的输入。 如果接受来自此类源的输入,则应该首先对其进行验证,然后传递给这些 API,以便防止 SQL 注入攻击之类的威胁。

命名空间:  System.Data.Entity.Migrations
程序集:  EntityFramework(在 EntityFramework.dll 中)

语法

声明
<SuppressMessageAttribute("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")> _
Protected Friend Sub AddPrimaryKey ( _
    table As String, _
    columns As String(), _
    name As String, _
    clustered As Boolean, _
    anonymousArguments As Object _
)
用法
Dim table As String 
Dim columns As String()
Dim name As String 
Dim clustered As Boolean 
Dim anonymousArguments As Object 

Me.AddPrimaryKey(table, columns, name, _
    clustered, anonymousArguments)
[SuppressMessageAttribute("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
protected internal void AddPrimaryKey(
    string table,
    string[] columns,
    string name,
    bool clustered,
    Object anonymousArguments
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1026:DefaultParametersShouldNotBeUsed")]
protected public:
void AddPrimaryKey(
    String^ table, 
    array<String^>^ columns, 
    String^ name, 
    bool clustered, 
    Object^ anonymousArguments
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")>]
member AddPrimaryKey : 
        table:string * 
        columns:string[] * 
        name:string * 
        clustered:bool * 
        anonymousArguments:Object -> unit
function AddPrimaryKey(
    table : String, 
    columns : String[], 
    name : String, 
    clustered : boolean, 
    anonymousArguments : Object
)

参数

  • table
    类型:System.String
    包含主键列的表。 架构名称是可选的,如果未指定架构,则将假定 dbo。
  • name
    类型:System.String
    数据库中的主键的名称。 如果未提供任何值,则将生成唯一名称。
  • clustered
    类型:System.Boolean
    指示此键是否是聚集的主键。
  • anonymousArguments
    类型:System.Object
    提供程序可能会处理的其他参数。 使用匿名类型语法指定参数,例如“ new { SampleArgument = "MyValue" }”。

请参阅

参考

DbMigration 类

AddPrimaryKey 重载

System.Data.Entity.Migrations 命名空间