entity-framework-core

The DbContext of type cannot be pooled because it does not have a single public constructor accepting a single parameter of type DbContextOptions

雨燕双飞 提交于 2019-12-30 01:15:16
问题 I am trying to upgrade our current .Net Core application from 1.1 to 2.0 and am getting this runtime error: "The DbContext of type 'CoreContext' cannot be pooled because it does not have a single public constructor accepting a single parameter of type DbContextOptions". It is caused by using the new IServiceCollection.AddDbContextPool<> function. When I use IServiceCollection.AddDbContext<> it still works. This application is DB-First, so I generate all our contexts using 'Scaffold-DbContext'

DbContext for background tasks via Dependency Injection

老子叫甜甜 提交于 2019-12-29 18:42:52
问题 I am probably not thinking in the right direction. I am fairly new to Dependency Injection and ASP.Net Core. I have a ASP.Net core website, and one of the tasks is to import data from an excel sheet to a database that a user will upload. The excel sheets can be huge and the data transformation tasks are time taking, hence I wish to perform them in the background. i.e. The user will upload the sheet, the response will be sent immediately and the background job/thread will import the data. I am

Blazor: A second operation started on this context before a previous operation completed

时间秒杀一切 提交于 2019-12-29 08:23:06
问题 I'm creating a server side Blazor app. The following code is in the Startup.cs . services.AddDbContext<MyContext>(o => o.UseSqlServer(Configuration.GetConnectionString("MyContext")), ServiceLifetime.Transient); services.AddTransient<MyViewModel, MyViewModel>(); And in the ViewModel: public class MyViewModel : INotifyPropertyChanged { public MyViewModel(MyContext referenceContext) { _myContext = myContext; } public async Task<IEnumerable<Dto>> GetList(string s) { return await _myContext.Table1

Blazor: A second operation started on this context before a previous operation completed

可紊 提交于 2019-12-29 08:23:04
问题 I'm creating a server side Blazor app. The following code is in the Startup.cs . services.AddDbContext<MyContext>(o => o.UseSqlServer(Configuration.GetConnectionString("MyContext")), ServiceLifetime.Transient); services.AddTransient<MyViewModel, MyViewModel>(); And in the ViewModel: public class MyViewModel : INotifyPropertyChanged { public MyViewModel(MyContext referenceContext) { _myContext = myContext; } public async Task<IEnumerable<Dto>> GetList(string s) { return await _myContext.Table1

Entity Framework Core Customize Scaffolding

别来无恙 提交于 2019-12-29 07:35:27
问题 I have done scaffolding of my SQLServer database. And it creates the POCO objects in the specified folder. What i would like to do is that it extends from my base class. I also use repository pattern so i need to have Id key on every entity and I don't want to change that each time i rescaffold the database. Scaffold Model Example public partial class Food { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } public double Price { get; set; } }

EF Core 2.0.0 Query Filter is Caching TenantId (Updated for 2.0.1+)

我怕爱的太早我们不能终老 提交于 2019-12-29 07:01:50
问题 I'm building a multi-tenant application, and am running into difficulties with what I think is EF Core caching the tenant id across requests. The only thing that seems to help is constantly rebuilding the application as I sign in and out of tenants. I thought it may have something to do with the IHttpContextAccessor instance being a singleton, but it can't be scoped, and when I sign in and out without rebuilding I can see the tenant's name change at the top of the page, so it's not the issue.

ASP.NET Core RC2 Seed Database

女生的网名这么多〃 提交于 2019-12-29 06:46:12
问题 My problem is i am trying to seed an Entity Framework Core database with data and in my mind the below code show work. I've realised that this should not be called in the ApplicationDbContext constructor and should be called from the startup but im not sure how to do this. EDIT: Based on the solution provided by Ketrex, my solution is as follows: Startup.cs: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ... app.ApplicationServices

Is there a DbSet<TEntity>.Local equivalent in Entity Framework 7?

不羁岁月 提交于 2019-12-29 06:45:12
问题 I need an ObservableCollection<TEntity> in EF7, DbSet<TEntity>.Local doesn't seem to exist; Is there any workaround? 回答1: Current version of EntityFramework (RC1-final) has no DbSet.Local feature. But! You can achieve something similar with current extension method: public static class Extensions { public static ObservableCollection<TEntity> GetLocal<TEntity>(this DbSet<TEntity> set) where TEntity : class { var context = set.GetService<DbContext>(); var data = context.ChangeTracker.Entries

How to log queries using Entity Framework 7?

别来无恙 提交于 2019-12-29 05:17:25
问题 I am using Entity Framework 7 on the nightly build channel (right now I'm using version EntityFramework.7.0.0-beta2-11524) and I'm trying to log the queries that EF generates just out of curiosity. I'm writing a simple console program, I tried using the same logging technic that EF6 uses, but DbContext.Database.Log is not available on Entity Framework 7. Is there a way to log or just take a peek at the SQL generated by EF7? 回答1: For those using EF7 none of the above worked for me. But this is

How do you configure the DbContext when creating Migrations in Entity Framework Core?

ぐ巨炮叔叔 提交于 2019-12-28 22:29:52
问题 Is there way that dependency injection can be configured/bootstrapped when using Entity Framework's migration commands? Entity Framework Core supports dependency injection for DbContext subclasses. This mechanism includes allowing for configuration of data access outside of of the DbContext . For example, the following would configure EF to persist to a SQL server using a connection string retrieved from config.json ServiceCollection services = ... var configuration = new Configuration()