Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrations: Entity Framework Core #161

Closed
5 tasks done
NickCraver opened this issue Mar 20, 2017 · 9 comments
Closed
5 tasks done

Integrations: Entity Framework Core #161

NickCraver opened this issue Mar 20, 2017 · 9 comments
Milestone

Comments

@NickCraver
Copy link
Member

NickCraver commented Mar 20, 2017

Originating in #130, need to see how Entity Framework Core works, likely create MiniProfiler.EntityFrameworkCore (or MiniProfiler.Providers.EntityFrameworkCore, depending on the integration) and get a sample in.

  • Investigate Entity Framework Core
    • ProfiledDbConnection
    • Events (possible they have profiling hooks already)
  • (If needed) Create MiniProfiler.Providers.EntityFrameworkCore package
  • Add Entity Framework Core to the ASP.NET Core MVC sample
@NickCraver NickCraver added this to the 4.0 Libs milestone Mar 20, 2017
@NickCraver
Copy link
Member Author

I'm working with the EF team on best approaches here: dotnet/efcore#7939

@NickCraver
Copy link
Member Author

Closing this out, a new package is available for testing: MiniProfiler.EntityFrameworkCore. I welcome issues anyone hits and it'll continue to progress as System.Diagnostics does.

@chadwackerman
Copy link

Works great. And "just works" with ASP.NET Identity (specifically Microsoft.AspNetCore.Identity.EntityFrameworkCore) which was always problematic with MVC in the past.

Inside Startup.Configure I had some database access. Initialization isn't fully complete yet (I believe MiniProfiler.Current isn't set) and it throws an exception in RelationalDiagnosticListener.cs/OnBeforeExecuteCommand.

Moving the database calls above app.UseMiniProfiler(...) is a workaround.

NickCraver added a commit that referenced this issue Apr 2, 2017
@NickCraver
Copy link
Member Author

@chadwackerman Doh, I'm stupid...not sure why I made that throw. Next build will include adbdca2 to fix that bad behavior.

@chadwackerman
Copy link

I believe I'm seeing a variation of this on alpha8-165.

Program.cs:

public static async Task Main(string[] args)
{
    var host = BuildWebHost(args);

    using (var scope = host.Services.CreateScope())
    {
        var services = scope.ServiceProvider;
        var db = services.GetRequiredService<ApplicationDbContext>();
        var foo = db.Whatever.FirstOrDefault(); // throws
    }

    host.Run();
}

public static IWebHost BuildWebHost(string[] args)
{
    return WebHost.CreateDefaultBuilder(args)
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();
}

If I remove .AddEntityFramework() from the services.AddMiniProfiler() call in Startup.cs, it works.

@NickCraver
Copy link
Member Author

What error does it throw?

@NickCraver NickCraver reopened this Sep 20, 2017
@chadwackerman
Copy link

chadwackerman commented Sep 20, 2017

System.NullReferenceException: Object reference not set to an instance of an object.
   at StackExchange.Profiling.Data.RelationalDiagnosticListener.OnNext(KeyValuePair 2 kv) in C:\projects\dotnet\src\MiniProfiler.EntityFrameworkCore\RelationalDiagnosticListener.cs:line 114
   at System.Diagnostics.DiagnosticListener.Write(String name, Object value)
   at Microsoft.EntityFrameworkCore.Internal.RelationalLoggerExtensions.ConnectionOpened(IDiagnosticsLogger`1 diagnostics, IRelationalConnection connection, DateTimeOffset startTime, TimeSpan duration, Boolean async)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.<OpenAsync>d__34.MoveNext()

@chadwackerman
Copy link

Fixed on alpha9-202

@NickCraver
Copy link
Member Author

Closing this out to clean up :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants