Entity Framework 4.1: Name constraints

后端 未结 2 1249
独厮守ぢ
独厮守ぢ 2021-01-15 10:35

We are working with entity framework 4.1 - code first. We need to be able to name our constraints and not have their names auto-generated by SQL Server. Is this possible?<

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-15 10:58

    Could you run some raw sql to rename them after creation? You may need to disable the EdmMetadata convention.

    context.Database.ExecuteSqlCommand(
      @"DECLARE @pk sysname
        SELECT @pk = name FROM sysobjects WHERE parent_obj = object_id('users') and xtype = 'pk'
        EXEC sp_rename @pk, 'pk_users_UserId'
    ");
    

提交回复
热议问题