Problem with AutoCrud

Hi, really enjoying the Auto Query features of ss. However I’ve hit an issue when using the AutoCrud feature from within an MVC Controller Action. I think I have things wired up corrected as when I run the (auto) Crud service ‘CreateCrudPerson’ from Application_Start it works great, including the Audit events. When I check my database the entries are there correctly.

However, when I run the Crud service from the Contact action in the Home controller, it seems to hang the database. Please see example project here https://github.com/simonwebber/sscrudissue.git

Thanks

The issue is because you’re trying to call AutoQuery’s Async Services from a Sync MVC Controller, effectively preventing the async Task’s continuation from being invoked.

You’ll need to use the Async Service Gateway APIs in Async MVC Actions instead, e.g:

public async Task<ActionResult> Contact()
{
    ViewBag.Message = "Your contact page.";
    var result = await Gateway.SendAsync(new CreateCrudPerson {
        Name = "FromContact"
    });
    return View();
}

In future when submitting repo’s, please just the publish the project source code in a GitHub repo without the bin and obj folders so the project can be viewed directly in GitHub without needing to download & extract large .zip. GitHub enables better visibility, e.g. can be annotated & linked to & fixes via PR’s.

It’s also safer as the NuGet packages can be restored directly from NuGet, instead of needing to locally scan untrusted binaries.

1 Like

Thanks - that’s working now and makes perfect sense.

Any idea why I can’t see the metadata page? I’ve tried /api/metadata and /metadata

Noted re future repos.

Your MVC ignore api route rule needs to be registered before the default controller route rule, e.g:

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

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
        routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
    }
}

When in doubt you can compare it to the working mvc-netfx project template, e.g. RouteConfig.cs