Questions tagged [dbcontext]

The DbContext API first shipped with Entity Framework version 4.1 and provides a more productive surface for working with the Entity Framework and can be used with the Code First, Database First, and Model First approaches.

The DbContext class represents a combination of the Unit-Of-Work and Repository patterns and enables you to query a database and group together changes that will then be written back to the store as a unit. DbContext is conceptually similar to ObjectContext.

Links:

2528 questions
0
votes
1 answer

I am struggling to remove entity using EF Core

using (var db = new MyDbContext()) { var removeFromDb = db.StockQuantities.Take(stockToRemoveCount).ToList(); for (int i = 0; i < removeFromDb.Count; i++) { db.Entry(removeFromDb[i]).State = EntityState.Deleted; …
0
votes
1 answer

DbContext interface in DDD

I read that Domain project shouldn't specify any ORM. So if I have to create interface for DbContext implemented in Infrastructture project, how can I do it? How can I specify all required DbSet? Interface in Domain project: public interface…
0
votes
1 answer

DBContext Inherit from multiple base class

I have just implemented the DuendeIdentity Server and by DBContext looks like this. public class DataContext : ApiAuthorizationDbContext { public DataContext( DbContextOptions options, …
Tim Cadieux
  • 447
  • 9
  • 21
0
votes
1 answer

How can we debug Entity framework core dbcontextPooling in c#

I want to check how DbcontextPooling is working internally and want to debug that, is there any way I will achieve that ? Thanks in advance.
Zeeshan
  • 484
  • 1
  • 5
  • 19
0
votes
1 answer

Adding DbContext for list of context types at runtime

To implement a plug-in system in a AspNet Core Mvc app, I would like a non-generic method to add a data context from a list of assemblies loaded dynamically at runtime, taking a Type parameter like this: foreach(Type tp in pluginContexts) { …
nepdev
  • 937
  • 1
  • 11
  • 19
0
votes
1 answer

Why DbContext Save Only One from List of Item?

I am using AspNetNet 6. In my Page I have two [BindProperty]: tblUserToRoute Class (Entity Class) int[] SelectedRouteIds (Get Selected Item By User) When client select several item in ListBox and click on save button, in my "OnPost" method I…
Hadi Mazareei
  • 31
  • 1
  • 7
0
votes
1 answer

Determine if SQLite database schema is current

I'm using SQLite and Entity Framework code-first. And my Windows desktop application needs the ability to Create and Open files. For creating a database, I found DbContext.Database.Migrate(), which will create the database if needed, and them make…
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
0
votes
1 answer

Complex C# LambdaExpression with polymorphic type

In short, here's what I am trying to do: register a HasQueryFilter lambda expression for entities in a DbContext.OnModelCreating where I am enumerating an unknown set of entities that I DO know implement an interface. The code (simplified for this…
Scott
  • 888
  • 7
  • 21
0
votes
3 answers

Dependency injection of Database context error

Hello I am trying to create an instance of the db in the constructor of the controller to be able to use it throughout the controller but it keep throwing an error. This is the error I am getting: InvalidOperationException: Unable to resolve service…
BUIBBE
  • 23
  • 1
  • 7
0
votes
0 answers

c# EF 6.2 Change dbContext modelBuilder default schema sql Server

I'm using entityframework 6.2.0, and I'm on a multi-tenant architecture, I have to change the schema every time I change the country. in the 1st access to the application I point to the correct schema, on the other hand if I change the country…
0
votes
1 answer

Migration issues after replacing IdentityDbContext with regular DbContext

Originally I was using IdentityDbContext for awhile. Everything was working and I was doing migrations and such. But recently I decided to let AWS Cognito handle the users and password thus no longer needing IdentityDbContext. So I switched my…
0
votes
1 answer

DbContext SaveChanges stuck on validation error, keeps throwing same validation error after changing data

I have a method to update data from a CSV with a DbContext. I deliberately uploaded some bad data so that I could test the output when there's a validation error. The data I uploaded had an invalid state, so I got the error Test.Entry@aol.com has…
Erica Stockwell-Alpert
  • 4,624
  • 10
  • 63
  • 130
0
votes
0 answers

How do I correctly declare and utilize a DBContext with a non-default constructor?

This is a follow up to a question I asked previously, regarding how to make a DBContext work with different connection strings. It turns out such a thing is possible, but I'm not sure how to modify my project to take advantage of it. The following…
bmurrell30
  • 565
  • 8
  • 23
0
votes
1 answer

DBContext fail No suitable constructor was found for entity type 'FolderNamespace'

I have a large Project with an DBContext create with great EFCore PowerTool and mySql On Debugging fails on load the EntitiesContext with System.InvalidOperationException: "No suitable constructor was found for entity type 'FolderNamespace'. The…
Wolfgang Schorge
  • 157
  • 1
  • 10
0
votes
2 answers

EF Core 3.1: Deleted all Migrations and the Database, how to recreate all tables in a new database?

I deleted all migrations in the migrations folder and also deleted the database in SQL Server. I know - now - these shouldn't be done, but I need to re-create the database structure to keep the application. I tried 'add-migration initial' but the it…