Base solution for your next web application

Activities of "rickwheeler"

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>();

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

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

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.

Question

Hi,

Just wondering if it is safe to disable Entity Framework Lazy Loading?

public MyDbContext()  : base("Default")
{
    this.Configuration.LazyLoadingEnabled = false;
}

I want to disable it in my DbContext but want to make sure it isn't going to cause any issues with ABP.

Thanks, Sean

Hi,

It is related.

It is to do with the way you are registering the routes and the order that they are registered in.

The problem is that by adding a catch all route inside of the RouteConfig.cs of the web project. It gets registered BEFORE the dynamic API routes.

Here is how I resolved the issue.

Step 1: Add a catch all route in the PostInitialize method. This will ensure that it is registered AFTER all others.

public override void PostInitialize()
        {
            var server = HttpContext.Current.Server;
            var appFolders = IocManager.Resolve<AppFolders>();

            appFolders.SampleProfileImagesFolder = server.MapPath("~/Common/Images/SampleProfilePics");
            appFolders.TempFileDownloadFolder = server.MapPath("~/Temp/Downloads");
            appFolders.WebLogsFolder = server.MapPath("~/App_Data/Logs");
            
            try { DirectoryHelper.CreateIfNotExists(appFolders.TempFileDownloadFolder); } catch { }

            // Register catch all here
            RouteTable.Routes.MapRoute(
                "CatchAll",
                "{*urlString}",
                new { controller = "CatchAll", action = "Index" }
            );
        }

Step 2: Update RouteConfig.cs with the following. We need to comment out the default route, map attribute routes and add explicit routes for scripts and views controllers

public static class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // Map attribute routes
            routes.MapMvcAttributeRoutes();

            //ASP.NET Web API Route Config
            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            routes.MapRoute(
                "Home",
                "",
                new { controller = "Page", action = "Home" }
            );

            // Add explicit routes for some ABP controllers that were being handled by the now commented out default route
            routes.MapRoute(
                "AbpScripts",
                "AbpScripts/{action}",
                defaults: new { controller = "AbpScripts" },
                namespaces: new [] { "Abp.Web.Mvc.Controllers" }
            );

            routes.MapRoute(
                "AbpAppView",
                "AbpAppView/{action}",
                defaults: new { controller = "AbpAppView" },
                namespaces: new[] { "Abp.Web.Mvc.Controllers" }
            );

            // Comment out old default route in order to define explicit attribute routes
            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            //    namespaces: new[] { "ProductsOnline.Web.Controllers" }
            //);
            
        }
    }

Step 3: Go through all Controllers and define explicit attribute routes as follows

[AbpMvcAuthorize]
    // Add explicit attribute routing
    [Route("profile/{action}/{id?}")]
    public class ProfileController : ProductsOnlineControllerBase
    {

<cite>exlnt: </cite> That file is already there. I updated the bundle reference to use "Darkblue" so that resolved the color issue. The menu still does not work. It will not expand when you click on it. Can you help me with that?

To fix this issue you need to edit YourApplication.Web>App>common>views>layout>sidebar.cshtml

You need to change this

<a href="javascript:;" class="auto" ng-if="childMenuItem.items.length">

To this

<a href="javascript:;" class="auto nav-link nav-toggle" ng-if="menuItem.items.length">

Hi,

If I define a route like the following underneath all routes in in the RouteConfig.cs, calls from the angular app to the dynamic API no longer work. Instead, they are passed to my CatchAllController as shown in the image.

routes.MapRoute(
                "CatchAll",
                "{*urlString}",
                new { controller = "CatchAllController", action = "Index" }
            );

This is a fairly major issue for us at the moment so any help on how to resolve the problem would be appreciated.

Perhaps it has to do with moving the order of precedence for dynamic api routes above my catch all route? The catch all route should be the very last option if no other routes were found.

Regards, Sean

Hi,

In Abp.Configuration.Setting.Value the string length is set to 2000.

I need the field to be NVARCHAR(MAX)

How would you suggest to accomplish this in an ABPZero template?

Regards, Sean

Hi,

I'm trying to write some code to create a new tenant from a console application.

  • Download ASP.NET Zero template
  • Add a new console application to the solution
  • Make it a module just like the Migrator tool using the same code for bootstrapper etc
  • Call TenantManager.CreateWithAdminUserAsync

When I do this, I receive the error "There is no permission with name: Pages.Tenants"

I have both data and core modules added as dependencies to my console application module. Are you able to replicate this problem?

Any help appreciated.

Cheers, Sean

Showing 1 to 10 of 24 entries