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

EF Core add multiple entities to IdentityDBContext with aspnetUser table

I have a IdentityDBContext which i would like to join to other entities via EF Core. Currently i am using the default authentication from the project creation. I am trying to figure out how i would join the id from the aspnetUsers table into…
John Pham
  • 65
  • 6
0
votes
0 answers

Using DbContextFactory for Data Seeding with SpecFlow tests

We are working on creating a suite of automated playwright tests for our app through specflow. I have been trying to come up with a way to use specflow hooks to seed data before/clean up data after each test so that we can ensure that no tests are…
Rain Code
  • 1
  • 2
0
votes
1 answer

Why is the Composite Key argument order inversed?

I have a simple Many to Many relationship in using C# .net Core 6 EF asp.net project. public class PageTag // : BaseEntity { [Key] [Column(Order =1)] public int TagId { get; set; } [Key] [Column(Order…
Ricky
  • 840
  • 1
  • 8
  • 11
0
votes
1 answer

Reorganizing codes after generating it using ADO.NET DbContext Generator

Suppose I am creating a application using the sample Northwind database using asp.net mvc 3 and entity framework database first approach. For that I am opening a new asp.net mvc 3 project and then adding a ado.net entity data model. I am generating…
Alim Ul Gias
  • 6,351
  • 2
  • 28
  • 39
0
votes
0 answers

.net core console app transient DI EF connection

i'm piecing together EF and DI, i have a beginners understanding in it and im trying to solve for the following (in the one solution); I have a web app (blazor web assembly) which has two projects (Client / Server) I have a separate console app…
0
votes
1 answer

EF Core failed to execute database update command "fail: Microsoft.EntityFrameworkCore.Database.Command[20102]"

I'm trying to run PM> database update . But print out the error message I used the entity (code-first) to create the database. But I manually added table in the sql server , then I added class.cs in the project , I did Update-database Then I made…
0
votes
1 answer

Domain classes not visible to Data layer (Application context class )

To make data-layer be aware of my domain classes, I've added a reference between the two class libraries, HMSContext (i.e., data-layer) and Hms.Entities (i.e., domain-classes). Following is code from HMS.Entities: namespace HMS.Entities { class…
Oxin
  • 31
  • 1
  • 7
0
votes
0 answers

How can I get a JOIN result from a dbcontext class to format and to send as a JSON string?

I'm doing some practice with Entity Framework and I want to create a web-api backend, which is able to manage requests by interacting with a MySql database and by responding with JSON strings in the message body of the replies. I'm quite new to it…
0
votes
1 answer

Is there a way to get an IObjectContextAdapter from an IdentityDbContext in EF?

I am getting the following error.. Exception thrown: 'System.InvalidCastException' in System.Private.CoreLib.dll: 'Unable to cast object of type 'Company.Data.SqlDbContext' to type…
0
votes
1 answer

Remove Data by multiple ID

I have a student management. I can insert,update and delete students. But deleting is only possible with one ID and I want to delete a student by specifying two IDs. What do I need to add or change? public void DeleteStudentByIDs(int ID1, int…
ITDummie
  • 3
  • 1
0
votes
1 answer

Converting IQueryable to List using EF core with postgres DB

I am using a postgres DB and EF core. I have the following code get data using DB context IQueryable projectIds = context.Projects.Where(x => x.Collaborators.Contains(userId)).Select(x => x.Id); List ids = projectIds.ToList(); When…
0
votes
0 answers

DBContext connection to SQL Server Express throws exception using the added app.config, what is missing?

Without using .net core, I worked on an existing .net framework 4.8 Console project that's missing app.config, trying to replicate the tutorial on how to create a dbContext to SQL Server Express. So I've added an app.config manually by googling, …
Datadump
  • 45
  • 6
0
votes
1 answer

Why won't my API's updated DbContext fetch a newly added DB column?

I have an Azure SQL DB that initially had the following columns: user name password hash password salt This DB serves a .NET Core C# API that checks username and password to return a JWT token. The API had a User object that comprised all three…
0
votes
1 answer

How to add second DbContext to existing EF project

I have an existing Ef DbContext (ApplicationDbContext) that connect to a MySql server with it's proper OnConfiguring and OnModelCreating function. Now I must add a new DbContext (GeoDbContext) to a different server. I add the GeoDbContext in…
Longa
  • 364
  • 4
  • 16
0
votes
1 answer

Is there a way to break DbContext to area in ASP.NET 6 framework?

I am creating a web application on the top of ASP.NET 6 framework. I am trying to figure out the best ORM to use for this project. I am leaning toward Entity Framework for the following reason I'll be able to use LINQ to write my queries I'll be…
Jay
  • 1,168
  • 13
  • 41
1 2 3
99
100