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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
6 views

Why some records are not retrieved ( EF6-Add-Migration with DbContext)

Created an API that retrieves data from SQL Server. I'm using an OnModelCreating() method to establish table relationship. Both parent has PK mykey, the child tables have a foreign key mykey. The ...
user2835586's user avatar
0 votes
1 answer
16 views

Unable to define table relationship to be used with Add-Migration

Apologize for duplication as I believe I did not ask question property (Reposting question) I have two models Movie and Category -The Movie class has a PK public Int64 MovieSer { get; set; } //PK -...
user2835586's user avatar
0 votes
0 answers
30 views

LinQ how to join data from two different contexts

I'm using query to delete some records need to be deleted from a context based on the status those ids have in another database. And if that record doesn't have that status in that external database, ...
Jose M Martin's user avatar
0 votes
0 answers
22 views

.NET 6 and Quartz.net how to use Dependency Injection for dbcontext?

I am using Quartz.net version 3.7 and need to inject DbContext in the constructor. How would i do it ? Not able to find a good example using .net6. public abstract class BaseJobMgr : IJob { private ...
gjo's user avatar
  • 23
1 vote
1 answer
54 views

Trouble with add-migration (Entity Framework Core)

Trying to run add-migration for a code-first database, but I'm getting this error: Unable to create an object of type 'StoreContext'. This is the error messages with -verbose: System....
6a9heast's user avatar
1 vote
1 answer
83 views

Add Or Update EF Core7

What is the most efficient way to implement add or update using Entity Framework Core 7 for IEnumerable<MyEntity> myentities? Tried to loop through each item and myDBContext.CustomAddUpdate(item)...
TrialByFire's user avatar
0 votes
1 answer
54 views

DbContext Update is not working but Get is working. Why?

I implemented Repository and UnitOfWork pattern in my Core Layer: public class Repository<TEntity, TContext> : UnitOfWork, IRepository<TEntity> where TEntity : class, new() where ...
Musa AKYUZ's user avatar
0 votes
1 answer
44 views

Filter Bindingsource and datagridview

I am trying to filter a bindingsource and display it in a datagridview. But it doesn't work. The binding source is filled by a database request Here is my code : private void SecteurForm_Load(...
Eraaz's user avatar
  • 19
1 vote
1 answer
66 views

Cannot create instance of type "" because one or more parameters cannot be bound to

I'm trying to create my own Web API with .NET 6 but before putting data into the database, but I get an error System.InvalidOperationException: 'Cannot create instance of type 'Hotelum.HotelsSeeder' ...
Insikt's user avatar
  • 21
0 votes
1 answer
86 views

Facing issue implementing Dbcontext in .net6

I'm facing issue with DbContext in ASP.NET Core 6 Web API, getting exception connection dispose or closed. Because I'm using the same DbContext across the application, I face this issue when database ...
Apire's user avatar
  • 9
0 votes
0 answers
46 views

How to make a DbSet property for a Model in DAL

I'm encountering an issue when attempting to add a new Razor View with a Create template and a model that uses DatabaseContext as its class. The error I'm facing is as follows: There was an error ...
Ashkan's user avatar
  • 1
0 votes
0 answers
52 views

How do I check if the seeded data I try to create is already in my database?

When trying to update my database, I stumble across the following error: Violation of PRIMARY KEY constraint 'PK_AvatarBase'. Cannot insert duplicate key in object 'dbo.AvatarBase'. The duplicate key ...
Wintrow Vestrit's user avatar
0 votes
1 answer
90 views

Why my query timeout after use the existing SqlConnection to new DbContext(DbConnection existingConnection, bool contextOwnsConnection)?

the DBContext support several method to initiate, previously I pass the connection string with user/password, and everything works well. public DbContext(string nameOrConnectionString) { Check....
feili's user avatar
  • 1
0 votes
2 answers
41 views

ASP.NET MVC initial controller set up using the context

This error occurs when using the default set up below InvalidOperationException: Unable to resolve service for type 'MangaShop.Data.MangashopContext' while attempting to activate 'MangaShop....
Killua's user avatar
  • 3
-3 votes
1 answer
35 views

BLAZOR WEBASSEMPLY and MYSQL WORKBRENCH - DbContext problem

I am using Mysql Workbench to connect in our server, how to use it in Blazor? What is this error? Win32Exception: The parameter is incorrect. SqlException: A network-related or instance-specific error ...
Asel Dev's user avatar
0 votes
0 answers
62 views

Cannot insert explicit value for identity column when SaveChanges

I have a model named AcademicLevel: public class EducationLevel { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public virtual ClassName ...
Fayyaz Ahmed Nadeem's user avatar
0 votes
1 answer
58 views

Why do I get database provider error in ASP.NET Core 7?

I have an ASP.NET Core 7 MVC project. I want put my SQL Server connection string in the appsettings.json file, and then use that in my entire project and the layers. But I get the the provider error: ...
sadegh's user avatar
  • 157
1 vote
1 answer
84 views

ASP.NET Core - Fetch API doesn't post data

I've been trying to create a ASP.NET core web app to send the data input on page to my server.I have one table that contains one row with dropdowns for the first three columns and a checkbox for the ...
Katie Lou's user avatar
0 votes
1 answer
37 views

Entity Framework using wrong tablename for table class when execute Scaffold-DbContext command

I use this code to generate my project models: Scaffold-DbContext "Server=.;User ID=*****;Password=*******;Database=*******;Trusted_Connection=True;Encrypt=False;" Microsoft....
hmahdavi's user avatar
  • 2,246
0 votes
0 answers
38 views

Changing databases

I have created an ASP.NET MVC application that integrates Entity Framework and is connected to database1. I created a new database that I want to use instead. How do I switch to database2? I tried ...
zowaayy's user avatar
0 votes
1 answer
84 views

Testing repository queries of Entity Framework with NSubstitute

I am trying mock my dbContext in order to test my repository queries/filters. I have tried now with in memory database or by mocking the db context. In both cases I can only get it working when i don'...
user3077796's user avatar
0 votes
1 answer
97 views

When to add dbcontext service to startup? [closed]

I have 2 different "design pattern" projects in Solution: 1-ChainOfResponsibiltyDesignPattern and 2-RepositoryDesignPattern : Context of ChainOfResponsibiltyDesignPattern startup of ...
Karayeniceri's user avatar
0 votes
1 answer
41 views

No database provider has been configured for this DbContext.A provider can be configured by overriding the 'DbContext.OnConfiguring' or 'AddDbContext'

I Have an Error No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the ...
Panda's user avatar
  • 1
0 votes
1 answer
113 views

how to dynamically add row to table in EF

I am trying to achieve the functionality where I can add/update/delete rows dynamically to any table using EF core. Table name is available as string. I have tried few ways but nothing seems working......
Abhash786's user avatar
  • 893
0 votes
0 answers
19 views

Using default constructor with unit-of-work

I am developing a project with unit-of-work and what I want to ask is whether the code is in the right place or not. Can you help me with this? Question: is it correct to use the context class in this ...
Kemal's user avatar
  • 7
-1 votes
1 answer
106 views

Error when Scaffold-DbContext with ConnectionString from appsettings.json, but works if manually specifying same connection string

I am trying to reverse create the C# code from an existing database. If I manually enter my connection string and type the command: Scaffold-DbContext 'Data Source=MyServer;Initial Catalog=MyCatalog;...
rs77can's user avatar
0 votes
0 answers
41 views

EF6 reading data with NOLOCK while using a single connection

I want one DBContext per API call while allowing me to use NOLOCK on some SELECT calls. I use unity's DI to manage the life cycle of my DBContext. I built some helper methods to help me with making ...
user1170104's user avatar
0 votes
1 answer
122 views

Transient Error: "too many connections for role" in ASP.NET Core project with PostgreSQL and Entity Framework Core

In my ASP.NET Core project, which uses PostgreSQL as the database and Entity Framework Core for data access, I'm running into a recurring problem. I'm getting the following error message on and off: {&...
Addison K. Samuel's user avatar
0 votes
0 answers
34 views

Getting error in Program.cs per HttpClient

System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: <name of my service) Lifetime: Singleton ImplementationType: &...
CarGuyDan1's user avatar
-2 votes
1 answer
58 views

Entity Framework Navigation Property is null despite being explicitely included

I have two tables: Fatture and FattureMail defined like this: Fatture public partial class Fatture { public int Id { get; set; } public string? IdentificativoSdi { get; set; } public ...
Alessandro's user avatar
1 vote
2 answers
110 views

Cancelling one EF Core query and continue with another throws an Exception

Before executing a query with pagination and a lot of filters, I call .CountAsync() on it. It turned out that, for some filter conditions, .CountAsync() takes a very long time to finish (because of ...
Lightbringer's user avatar
2 votes
1 answer
90 views

Using OWIN in an ASP.NET MVC application, why do I obtain a DbContext disposed (InvalidOperationException) randomly?

I know this question is too general for SO, and I would’t be surprised if it’ll be closed. Anyway, I try to post here my problem, being sorry if it doesn’t belong here. I’m working on an ASP.NET MVC ...
Pine Code's user avatar
  • 2,446
0 votes
2 answers
59 views

Can the same EF db context be used in consecutive calls

I am working with Entity Framework inside an Azure function app and I got a DbContext class which initialize the db model. There is also a class called DbManage which is using the DbContext to perform ...
CodeMonkey's user avatar
  • 11.5k
-1 votes
1 answer
339 views

How to use Scaffold-DbContext in .NET Core for Sqlite database

I'm using .NET Core Version 7 and I want to use EF Core to access a Sqlite (*.db3) database file. This file has a password and I want to add the database tables to the project through database first. ...
Mohammad Hasan Salmanian's user avatar
0 votes
2 answers
33 views

DbContext returning some null values

I'm using return _dbContext.Groups; in my repository, it returns all my group objects but one object return null value field in TeamLeader. Here are my class in Group public class Group { [Key] ...
tomato_ketch's user avatar
0 votes
1 answer
19 views

Error when trying to insert many-to-many after saving new entity in Entity Framework

The problem that I'm stuck on consists of the following steps. I hesitate which approach is the right one - I want to save a new entity, part of many-to-many relation. After saving it I want to update ...
maria8829's user avatar
0 votes
2 answers
99 views

EF Core doesn't recognize new column name from database

Used scaffolding to connect to my database (mapping to a view). To the same DbContext I manually added two DbSets for a stored procedure. The first stored procedure is working perfectly. In one of the ...
bbWebDev's user avatar
0 votes
0 answers
10 views

Domain Driver Design after passing controller in another thread context lost. (Dot Net Core)

In my DDD dot net core projects all service instance created . at the end of controller method, started a thread of action method in same controller. But when the method start to get data it lost ...
Iftakhar alm's user avatar
0 votes
1 answer
53 views

Identity Entity Framework in IdentityDbContext change all Identity class to custom class

my old context is like public class MYDbContext : IdentityDbContext<IdentityUser, IdentityRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim> { } but I need some custom ...
roy adam's user avatar
0 votes
0 answers
24 views

DbContextFactory InvalidOperationException in Blazor App

I’ve changed my use of DbContext to incorporating DbContextFactory in order to handle multiple sql transactions. I’ve run into a couple questions/errors trying to do this. I have 3 different tables ...
AGeist's user avatar
  • 3
0 votes
1 answer
57 views

Unable create object of type 'DBContext'. For the different design patterns supported at design time,

While I was adding migration for my DBContext in visual studio with .net 7, I faced this error: An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the ...
Rachel Karen Green's user avatar
0 votes
1 answer
97 views

Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'ApplicationDbContext' has not been registered

I get an error at the starting of the application: An error occurred while trying to connect to the DB.(Myproj.Web.Program) Autofac.Core.Registration.ComponentNotRegisteredException: The requested ...
serge's user avatar
  • 14.3k
0 votes
1 answer
85 views

Getting error when trying to update to my database in Blazor Server Application

I'm getting the following error when trying to update to my database: System.InvalidOperationException: 'The instance of entity type 'Expense' cannot be tracked because another instance with the same ...
AGeist's user avatar
  • 3
1 vote
1 answer
72 views

EF Core: Exclude already written items from tracking

I have two entities with relation many-to-many. class Action { public int Id {get;set;} public List<Case> Cases{ get; set; } = new(); } class Case { public int Id {get;set;} ...
Nikolas's user avatar
  • 13
-1 votes
1 answer
84 views

Can't receive data from SQL query in string into a custom model In Entity Framework Core

enter image description here I'm trying to get the result of the query into a custom model that I created but I get an error: Cannot create a DbSet for 'POEntry' because this type is not included in ...
Mina Latif's user avatar
1 vote
1 answer
223 views

How do I fix `System.MissingMethodException: Constructor on type Microsoft.EntityFrameworkCore.DbSet`1 not found.`?

Database Table Export to CSV using EntityFramework DbContext .NET 6 I have been tasked to create a Blazor ASP.NET Core application that will export each table from an MS SQL Server database into it's ...
Tyson Gibby's user avatar
  • 3,092
1 vote
2 answers
34 views

Error on postgres migration files creation for dotnet

I read book Ultimate ASP.NET Core Web API. And there is a code first database creation using DbContext and IDesignTimeDbContextFactory<>. public class RepositoryContextFactory : ...
ilumini's user avatar
  • 19
0 votes
0 answers
33 views

Moving DBcontext registration to the data layer (.Net Core Web App)

I have a general question of how best to move the DBcontext from the web app to the data layer. The main reason is, I feel it's unnecessary for the Web layer to contain references to Entity Framework ...
sman's user avatar
  • 9
1 vote
0 answers
39 views

DbContextOptionsBuilder optionsBuilder optionsBuilder.isConfigured is always false

I am using two db context one for Identity and one for ef core. The ApplicationDbContext intity framework works. The SKGDMD_WebSiteContext is created by EF core power tools. It says to do what I have ...
cbas007's user avatar
  • 11
1 vote
0 answers
17 views

Calling Event Handler and using DBContext inside throws "disposed context" exception [duplicate]

I have a Service that handles a file upload. After the upload is finished, I'm raising the upload complete event. Inside the event, I want to set the "upload finished" state and write the &...
mimimi's user avatar
  • 33

1
2 3 4 5
51