How to use Update.Table in 4.50.x?

7 месяцев назад
Hi, I have a scenario where I need to perform a migration with the following actions:
1. add an external ID as nullable
2. populate the ID with required values
3. set the external ID as non-nullable and add foreign key to it

Normally I would do that with a mix of Alter.Table, Update.Table, Alter.Column as per https://fluentmigrator.github.io/articles/fluent-interface.html but it seems that in nopCommerce the Fluent Migrator is missing FluentMigrator.Builders.Update.Table

Am I doing something wrong or is FluentMigrator.Builders.Update.Table indeed missing? If so why and how to work around this?

Thanks
7 месяцев назад
Would this work?
// Add an external ID as nullable
Alter.Table("YourTableNameHere")
    .AddColumn("ExternalId")
    .AsInt32().Nullable();

// Populate the ID with required values
Execute.Sql("UPDATE YourTableNameHere SET ExternalId = 123 WHERE YourConditionHere");

// Set the external ID as non-nullable and add a foreign key
Alter.Table("YourTableNameHere")
    .AlterColumn("ExternalId")
    .AsInt32().NotNullable()
    .ForeignKey("FK_YourTableNameHere_ExternalId", "YourReferenceTableNameHere", "YourReferenceIdColumnNameHere");
7 месяцев назад
New York wrote:
Would this work?

Execute.Sql("UPDATE YourTableNameHere SET ExternalId = 123 WHERE YourConditionHere");


It seems that FluentMigrator functionality is reduced in NopCommerce. For example FluentMigrator.Builders.Execute.Sql and FluentMigrator.Builders.Update.Table seem to exist

I ended up solving it with:
await _nopDataProvider.ExecuteNonQueryAsync(""UPDATE YourTableNameHere SET ExternalId = 123 WHERE YourConditionHere;");


Would be good to hear back from NopCommerce team to better understand why FluentMigrator features were reduced or if I'm missing anything.
7 месяцев назад
nmrspm wrote:
Hi, I have a scenario where I need to perform a migration with the following
Am I doing something wrong or is FluentMigrator.Builders.Update.Table indeed missing? If so why and how to work around this?

Thanks


If you need access to Update construct, you must inherit your migration from the FluentMigrator.Migration abstract class.
7 месяцев назад
alexey.a wrote:

If you need access to Update construct, you must inherit your migration from the FluentMigrator.Migration abstract class.


Thanks Alexey, this is what I was missing!