Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Depends on the version of EF you are using. Even with migrations the result that you will see is something like:</p> <p>"drop column Id " and "add column TeamId".</p> <p>With this you will lose all values and "child connections"...... </p> <p>The only "secure" solution I am seeing at this point is a mix of Migrations and "hand SQL operations".</p> <p>EASY solution:</p> <p>1- taking in consideration that you already have a "base" migration creating the table with ID, now create the new migration with the "update". Now do NOT run it yet. </p> <p>2- Open that file and write a new line BEFORE the generated lines and use a SQL command, something like this:</p> <pre><code> SQL("ALTER TABLE table_name RENAME COLUMN old_name to new_name;"); </code></pre> <p>This will change the name BEFORE the migration deletes the column and create a new one, what will happen is: you change the name before the delete, then the delete is executed but it will "fail" but it will not hurt nothing. </p> <p>But now you ask: why do I do this? well if you are using migrations even if you delete the lines to delete the column and create a new one, the next time you create automatically a new migration file this new lines will be there...... this is why.</p> <p><strong>UPDATED ANSWERS #1</strong></p> <p>When I talk about Entity Framework Migrations I am referring to this: <a href="http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx" rel="noreferrer">http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx</a> When you Run the ‘Add-Migration AddBlogUrl’ command in Package Manager Console, a new file (*.cs) is created.</p> <p>Example of this file migration file with SQL commands:</p> <pre><code>public partial class AddAbsencesTypesAndCategories : DbMigration { public override void Up() { CreateTable( "pvw_AbsenceType", c =&gt; new { Id = c.Int(nullable: false, identity: true), Name = c.String(nullable: false), CountAsVacation = c.Boolean(nullable: false), IsIncremental = c.Boolean(nullable: false), }) .PrimaryKey(t =&gt; t.Id); ..... AddColumn("pvw_Absence", "CategoryId", c =&gt; c.Int(nullable: false)); AddForeignKey("pvw_Absence", "StatusId", "pvw_AbsenceStatusType", "Id"); AddForeignKey("pvw_Absence", "CategoryId", "pvw_AbsenceType", "Id"); CreateIndex("pvw_Absence", "StatusId"); CreateIndex("pvw_Absence", "CategoryId"); DropColumn("pvw_Absence", "MainCategoryId"); DropColumn("pvw_Absence", "SubCategoryId"); ...... Sql(@" SET IDENTITY_INSERT [dbo].[pvw_AbsenceStatusType] ON INSERT pvw_AbsenceStatusType (Id, Name) VALUES (1, N'Entwurf') SET IDENTITY_INSERT [dbo].[pvw_AbsenceStatusType] OFF "); ..... } public override void Down() { ........ } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload