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

How do I use a Blazor dependency method in @bind for a checkbox?

I have dependency ICollectionService: public class CollectionService : ICollectionService { public async Task IsObtained(int gameId) { using (DatabaseContext context = _contextFactory.CreateDbContext()) { …
0
votes
0 answers

Questions about using the same DbContext across multiple microservices

I have some questions and concerns about how to properly use the same DbContext connected to the same SQL Server DB, across multiple microservices. My Problem Currently, our software only uses a DbContext in one of our several microservices. This…
LoganCodes
  • 61
  • 3
0
votes
0 answers

Auto detach entity from dbcontext

services.AddDbContextPool(options => options.UseSqlServer(GlobalConfig.Configuration["ConnectionStrings:DefaultConnection"], b => b.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery)) …
0
votes
2 answers

Checking if a record exist returns "Sequence contains more than one matching element." for Net5 with Entity Framework 5

I have an .Net5 solution using Entity Framework 5.0.0. Im able to save data to the Backend SQL DB and all is well. But when I try to check is a record exist using the statement below im getting an error "Sequence contains more than one matching…
O'Neil Tomlinson
  • 702
  • 1
  • 6
  • 28
0
votes
0 answers

EF core 5.0 inserting duplicate records

Why is Entity Framework 5.0 inserting duplicate records in the Database in uncertain behavior when using dbcontext.AddAsync() then dbcontext.SaveChanges() method for adding data. I have checked the existing value from records before inserting but…
0
votes
1 answer

csharp(CS1660) | "Cannot convert lambda expression to type 'bool' because it is not a delegate type" with "HasMany Method"

so I want to create the relationships between my Model classes (Booking and Person). I found a tutorial for that here. I need the HasMany - WithMany Methods. When I try HasOne everything works fine. But as soon as I switch it to HasMany the error…
Joshua
  • 51
  • 1
  • 8
0
votes
0 answers

MemoryCache's Callback runs on new thread & classes are “dependency injected” as Transients, DBContext gives “Cannot access a disposed context” error

( Related Posting: Why is DBContext is disposed after putting it in IMemoryCache (.NET Core / EF Core) ) ( Related Posting: Cannot access a disposed object with MemoryCache ) Here is info about our technical development environment : Microsoft…
0
votes
1 answer

Update related entities Entity Framework DbContext

I'm using EF with a DbContext and several POCO entities public class Customer { public int ID { get; set; } public string CompanyName { get; set; } public string Address { get; set; } public string Email {…
Francesco
  • 964
  • 2
  • 17
  • 41
0
votes
1 answer

VS2022 .NET 6.0 Scaffold-DbContext command error: Invalid column name for non-existent column

I am trying to create model entities for use in LINQ in .NET Core 6.0 in VS 2022 since .edmx files are now deprecated. I am connecting to an existing SQL Server db at an external ISP using sql authentication. The db has compatibility level SQL…
0
votes
1 answer

How to use Entity Framework to upload data?

I have this web written in C# , that provides a table for user with these data ( ID , FROM , TITLE , MESSAGE ) Table name on database is MessagesTable My question is how can I use Entity Framework to upload data on the table , I used to do it using…
Maya
  • 3
  • 4
0
votes
1 answer

How to query EF Core dbcontext for specific attributes from navigation properties?

I'm trying to get the most efficient query for selecting some nested attributes in navigation properties so the API sends a response which contains only relevant information. So far I tried the Include() and ThenInclude() approach and the answer on…
Cbas G
  • 3
  • 1
  • 1
0
votes
1 answer

Hi, I am Using Expando Object to List two different model data on a View in Asp.net core Mvc, But I also want link a model named comments to sameView

Error: InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Dynamic.ExpandoObject', but this ViewDataDictionary instance requires a model item of type 'MyProject.Models.Comments'. This is My ViewResult: …
0
votes
0 answers

Using ICollection in Rest API Controllers to get specific Data

So I'm building my first Rest API and I have those 3 Model classes. And here is my DbContext Now I want to do this: I want to create a GET Method in the DeskController that shows me every Desk where bookings = null. I tried to construct it…
Joshua
  • 51
  • 1
  • 8
0
votes
1 answer

Reading data with EF 6 in a Singleton Class

I'm working on a .Net 6 API that uses a Service Layer to do all the business logic of the Controllers. And I'm trying to use EF 6 on this layer using the "using" statement to be able to use de dbContext in a Singleton class. The problem is that once…
Luis Agudo
  • 71
  • 1
  • 11
0
votes
2 answers

How to update models and DBContext class in Entity Framework core (if database created first)

As the title indicates I Have an SQL server database already made and I excuted the following command to generate DBContext class and the model: Scaffold-DbContext "connectionstring" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models later…
1 2 3
99
100