Base solution for your next web application

Activities of "rickwheeler"

Hi,

What are you suggestions for upgrading from v3.4.0 to v4.0.0?

I seem to have been able to update all of my source code just fine. The issue I have is with the database.

Since you've swapped from EF6 to EFCore, this has caused a major problem as there is a missing migration.

It appears that between 3.4.0 and 4.0.0 of AspNetZero that there were a lot of database changes. Since the EntityFrameworkCore project assumes there is no existing database and only includes an Initial migration I have no real way to upgrade my database which is on v3.4.0.

The changes seem to include the removal of some tables, column additions to some entities such as user, changes to indexes and more.

Do you have any suggestions for how to accomplish upgrading the database?

Thanks.

Thank you. I was able to figure out what these were via SQL schema compare but it is good to have it confirmed.

I also was able to figure out that if you follow the process below, you can create migrations to handle this upgrade

  • Remove all code from the up and down methods of the Initial_Migration.cs
  • run update-database
  • Delete all the code from the Initial_Migration.Designer.cs and the DbContextModelSnapshop.cs related to the tables and columns you mentioned above
  • Run add-migration V340ToV400
  • This migration should include the code to add the missing tables and columns
  • Add the following code to the bottom of the up method to set the normalized fields to the correct values
migrationBuilder.Sql("UPDATE AbpUsers SET NormalizedUserName = UPPER(UserName)");
migrationBuilder.Sql("UPDATE AbpUsers SET NormalizedEmailAddress = UPPER(EmailAddress)");
migrationBuilder.Sql("UPDATE AbpRoles SET NormalizedName = UPPER(Name)");
  • run update-database

Since lazy loading is not yet added to EF Core, how do I eager load related entities for all get methods?

For example:

public class MyEntity : Entity
{
    public int MyRelatedEntityId { get; set; }
    public MyRelatedEntity Related { get; set; }
}

How do I make sure that all methods on IRepository<MyEntity> eager load and include MyRelatedEntity? This includes GetAll, GetById, Find etc

I think I figured it out.

Make a custom Repository in the EfCore project like this

public class MyEntityRepository :MyAppRepositoryBase<MyEntity>, IRepository<MyEntity>
{
    public MyEntityRepository(IDbContextProvider<MyAppDbContext> dbContextProvider) : base(dbContextProvider) { }

    public override IQueryable<MyEntity> GetAll()
    {
        return base.GetAll().Include(x => x.MyRelatedEntity);
    }
}

Then in the PreInitialize method of EntityFrameworkCoreModule

Configuration.ReplaceService<IRepository<MyEntity>, MyEntityRepository>();
Showing 21 to 24 of 24 entries