First - thank you for your help!
I'm working through the tutorial in the APress book: Pro Entity Framework Coe 2 for ASAP.NET Core MVC without any problems.
I'd like to use OMR Profiler to view the SQL EF is sending to SQL Server, so if the profiler
is meant to be used with the LLBLGen Pro ORM product only just let me know.
--
The ORM Profiler docs are very clear and explicit, so the problem and help I'm asking for clearly has to do with pilot error not the product.
I simply don't understand where I need to apply the ORM Pofiler initialization code and was hoping you could point me in the right direction.
I've included the entire Startup.cs class for reference at the bottom.
Here is how I connect to the database currently:
string conString = Configuration["ConnectionStrings:DefaultConnection"];
services.AddDbContext<DataContext>(options =>
{
options.EnableSensitiveDataLogging();
options.UseSqlServer(conString, providerOptions => providerOptions.CommandTimeout(60));
});
How do I initialize the ORM Profiler given the code above?
I just don't see a DbProviderFactory or DbConnection anywhere in my project to exploit per the docs.
--
Tech tools and versions:
Target Framework: .NET Core 2.1
Output type: Console Application
OrmProfiler.exe = 2.0.1
SD Interceptor installed via NuGet:
SD.Tools.OrmProfiler.Interceptor.NetCore = 2.0.0
--
Here is my Startup.cs class:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SportsStore.Models;
namespace SportsStore
{
public class Startup
{
public Startup(IConfiguration config) => Configuration = config;
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit [https://go.microsoft.com/fwlink/?LinkID=398940](https://go.microsoft.com/fwlink/?LinkID=398940)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddTransient<IRepository, DataRepository>();
services.AddTransient<ICategoryRepository, CategoryRepository>();
services.AddTransient<IOrdersRepository, OrdersRepository>();
string conString = Configuration["ConnectionStrings:DefaultConnection"];
services.AddDbContext<DataContext>(options =>
{
options.EnableSensitiveDataLogging();
options.UseSqlServer(conString, providerOptions => providerOptions.CommandTimeout(60));
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseStatusCodePages();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
}
}
--
The ORM Profiler docs state:
.NET Core 2.0+
At startup of your application, where a DbProviderFactory is used to initialize your data access technology,
you have to use the InterceptorCore to wrap the DbProviderFactory with one provided by the interceptor so
it can track the activity and how long each action takes.
using SD.Tools.OrmProfiler.Interceptor;
//...
// example factory here is the SqlClient factory. You should provide the
// factory you're using on .NET Core for your database type, e.g.
// Oracle.ManagedDataAccess.Client.OracleClientFactory for Oracle
var wrappedType = InterceptorCore.Initialize("application name",
typeof(System.Data.SqlClient.SqlClientFactory));
// pass wrappedType now to your data access technology you're using instead of the
// type passed to Initialize();
--
If your data access technology uses a DbConnection instance instead of a DbProviderFactory type,
you can create one from the wrapped factory type by using:
var connection = wrappedType.Instance.CreateConnection();
// now pass 'connection' to your data access technology