Click here to Skip to main content
15,887,875 members
Everything / Entity Framework

Entity Framework

entity-framework

Great Reads

by Jovan Popovic(MSFT)
Mapping properties in EF model to database columns that contain JSON
by Kenji Elzerman
Fundamentals of Entity Framework
by Akhil Mittal
Entity framework core, code first migrations and data annotations in EF Core
by Jean Carlo S. Passos
CRUD over Association Entity that maps to association tables

Latest Articles

by GabrieleTronchin
In this project, I've implemented the Transactional Outbox Pattern using EF Core.
by David_Cui
To introduce a free library to save some tedious work for writing mapping code between entities and DTOs
by Mark Pelf
Fix for adding new DB tables does not work in VS 2022, ver. 17.6.2, EF6 (Classic)
by Mark Pelf
Tutorial on EF7 – Code First approach using Command Line (CLI)

All Articles

Sort by Updated

Entity Framework 

U 24 Apr 2024 by Dave Kreskowiak
This has nothing to do with migrations at all. The exception is telling you that you haven't configured your DbContext implementation with a database engine to use. Take a look at your code: protected override void...
U 24 Apr 2024 by Member 11307750
I am trying to add migartion to my datavase i keep having this error.Please i am a rookie to MVC Error Message Unable to create a 'DbContext' of type ''. The exception 'No database provider has been configured for this DbContext. A provider...
U 16 Apr 2024 by GabrieleTronchin
In this project, I've implemented the Transactional Outbox Pattern using EF Core.
21 Dec 2023 by Richard Deeming
You are performing an INNER JOIN - you will only get back results from the Addresses table which have a corresponding record in the ExtraData table. If you want all records from the Addresses table, even if they have no corresponding record in...
21 Dec 2023 by Sascha Manns
I have two tables in a database what i want to combine and work with that data. So i used that codesnippet: var listOfFoundRespIds = (from a in context.Adresses join e in context.ExtraData on a.LFD equals e.lfd where...
19 Dec 2023 by Richard Deeming
Since your repository code is swallowing all exceptions - an extremely bad idea, by the way! - the only reason for a NullReferenceException would be that the baseRepository is null. Check the constructor to make sure you've assigned the field...
18 Dec 2023 by A Belal
in Repository Pattern System.NullReferenceException Delete Method System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=Microsoft.EntityFrameworkCore StackTrace: at...
18 Dec 2023 by M Imran Ansari
As the error message, the issue is in Delete method. The Delete method attempts to remove an entity from the context using LapShopContext.Set().Remove(entity). However, the error you're encountering is a NullReferenceException, which suggests...
20 Nov 2023 by Richard Deeming
You have no [Authorize] attribute on your ValuesController or any of its actions. Unless you have some configuration that you haven't shown, all of those actions will allow anonymous callers. Simple authorization in ASP.NET Core | Microsoft Learn[^]
20 Nov 2023 by Andre Oosthuizen
Ok, so first - to run some error checking outside of your app, clear your browser cache or any other caching mechanisms that might be storing the old token as this might become an issue. I have converted your code to what I think might work,...
20 Nov 2023 by A Belal
I get tokenKey from path https://localhost:7107/api/login And when i try to test token and get data from Path https://localhost:7107/api/Values the token work good and data comes well but when i remove token the data continue come and...
6 Nov 2023 by Maciej Los
I'd strongly suggest to read this: Working with Stored Procedure in Entity Framework Core[^]
22 Oct 2023 by David_Cui
To introduce a free library to save some tedious work for writing mapping code between entities and DTOs
3 Oct 2023 by ahmed_sa
I work on Blazor application server side. I design web API to interact with razor pages. My issue is which is suitable for my scenario? Using ADO.NET or Entity Framework Core? What I try is as below: So is using data reader ADO.NET better or...
2 Oct 2023 by Graeme_Grant
I would compare EF Core with Dapper, not Ado.Net. Here are a couple of videos that go into detail... * Entity Framework Core vs Dapper Performance in 2023 - YouTube[^] * Making Entity Framework Core As Fast As Dapper - YouTube[^]
14 Sep 2023 by Richard Deeming
At a guess, you're trying to connect to .\SQLEXPRESS or something equivalent, which requires that the SQL instance is running on the same machine as your code. In which case, you need to update your connection string to point to the correct...
14 Sep 2023 by dolce_sweet
I have created a Maui Blazor app in .NET 7 which is pretty neat and runs beautifully locally. After installing the app on another Windows 10 Pro x64 machine, I get an error message that SQL Server Express (2019) cannot be reached. I get this...
14 Sep 2023 by HobbyProggy
As I am newly learning EF and wanted to migrate the existing "I write my own queries, that's way cooler" to something more stable and better to work with. Now I came across the question on how I can actually use the benefits of the relations...
22 Aug 2023 by HobbyProggy
So it worked with using modelBuilder.Entity() .HasOne(emt => emt.BaseInformationOfTemplate) .WithOne() .HasForeignKey(tib =>...
22 Aug 2023 by Richard Deeming
Quote: A futher interesting behaviour is, that if i load the "TemplateInformationBase" List first and then the "ChangeManagementTemplate" List, the Property of BaseInformationOfTemplate is filled with the data of the table. If i don't load the...
21 Aug 2023 by OriginalGriff
Read the error message carefully:Quote: he relationship from 'ChangeManagementTemplate.BaseInformationOfTemplate' to 'TemplateInformationBase' with foreign key properties {'IdTemplateInformationBase' : int?} cannot target the primary key...
25 Jul 2023 by Member 13304618
I have a design question; thus, no code samples I am trying to create a Web API Core project that would use an EF Core to communicate with a database. I read about the Data Access design pattern and realize that I have to place a Web API project...
25 Jul 2023 by Richard Deeming
Quote: the EF core cannot reference the Web API You've just answered your own question: the mapping needs to be done in a project which has references to both the entity classes and the DTOs you're mapping to. Personally, I'd be inclined to...
24 Jul 2023 by Richard Deeming
You'll want to start by getting rid of that reflection! Add a couple of methods to your DTO: public IEnumerable AllMovieNames() { if (!string.IsNullOrEmpty(MovieName1)) yield return MovieName1; if...
24 Jul 2023 by Member 11072126
I am trying to develop an API which will be taking few movie names as part of ViewModel and will be setting respective movie IDs in DTO. The table representation for TBL_Movies (For example I have used only 5 data but in real there are quite...
8 Jul 2023 by ahmed_sa
I work on asp.net core entity framework I have csharp function done using ado dotnet stored proceure i need to convert it using entity framwork core with another meaning how to call stored proceure using entity framework core 6 and i don't...
6 Jun 2023 by Mark Pelf
Fix for adding new DB tables does not work in VS 2022, ver. 17.6.2, EF6 (Classic)
4 Jun 2023 by Uwakpeter
I created MVC application using the DB first approach in VS 2022, after adding the Entity Data Model to the application, the model.tt did not generate database tables as classes! What I have tried: I have deleted the EDM file multiple times,...
4 Jun 2023 by Graeme_Grant
Check out this recent article, it will walk you through the process: Entity Framework 7 – Database First – Using EFCorePowerTools[^]
4 Jun 2023 by Gcobani Mkontwana
Hi Team I am having an issue with my crud application, basically this application uses business logic, entity framework for specific reason of the requirement. But the problem is when View is created and try to run this file 'Order/Edit.cshtml...
4 Jun 2023 by OriginalGriff
To add to what Graeme has said ... When you create a class the system adds a hidden default parameterless constructor for you so that you can create instances: public partial class MyClass { public MyClass() {} // Hidden constructor }...
4 Jun 2023 by Graeme_Grant
No parameterless constructor defined for this object. This is quite clear... This is a parameter constructor class: public class MyParameterClass { #region Constructors public MyParameterClass(int param1, int param2) { } #end...
1 Jun 2023 by Mark Pelf
Tutorial on EF7 – Code First approach using Command Line (CLI)
25 May 2023 by Mark Pelf
Tutorial on EF7 – Database First approach using GUI tools EFCorePowerTools
25 May 2023 by Mark Pelf
Tutorial on EF7 – Database First approach using Command Line (CLI)
19 May 2023 by Graeme_Grant
Being a Linq statement, it will not execute against the database until you start iterating over the results or calling a ToList(). This is why you are getting the System.InvalidCastException.
19 May 2023 by Hans-Jörg Eitner
Der Beginn meines Programms startet einen Integrationstest, der über einen Tupel zwei Wertpapierbestandslisten vergleicht. Die erste Liste enthält die Wertpapiere einer eingelesenen csv – Datei eines Depots. Die zweite Liste enthält die...
20 Apr 2023 by Yogeesha Naik
Validation failed for one or more entities. See entityvalidationerrors property for more details.[edit]SHOUTING removed - OriginalGriff[/edit]
20 Apr 2023 by Member 15984037
All good suggestions above. In fact, I solved my issue using Yogeesha's catch block above. It may be important to file this error away in your head, because you may run into this again. For me, I was passing a null value into a table field...
19 Apr 2023 by Max Speed 2022
hi guys,i Added a "service-based database" into my project with this name : "database2.mdf" and connected to this DB from Server Explorer and i made a Table with this name:"UserTbl" and this table has 2x column with this names : "Id,Name". Next...
19 Apr 2023 by Dave Kreskowiak
Sooo many problems in such a small amount of code. Where do I start? Well, why would you want to create two instances of the UserTbl class when you need to add just a single user? First, your UserTbl class needs an overhaul. You're thinking in...
16 Apr 2023 by mtoha
Hello, My app is working well. But when I try to create unit test, the entity framework is not working well I am trying to make Unit Testing for my Entity Framework, but when I try to get data / write data from server I am getting this error: ...
16 Apr 2023 by Graeme_Grant
REcommend that you check the documentation: Overview of testing applications that use EF Core - EF Core | Microsoft Learn[^] More information here, including YouTube instructional videos here: unit testing with entity framework - Google Search[^]
2 Apr 2023 by Marc Clifton
Using EntityFramework Core and SQL Server to create a dynamic IQueryable filtering that is not susceptible to SQL injection attacks
14 Mar 2023 by soufi web
Hi I want to move or (copy to t2 and delete from t1 )all data from table1 to table2 using Entity Framework, they have the same fields, and most of the answers talk about .Core or asp.net. I'm using EF6. Please Help me Thanks a lot What I have...
11 Mar 2023 by Dave Kreskowiak
The query does work. It's doing exactly what you told it to do. The problem you have is that it's your understanding of the query that isn't correct.
11 Mar 2023 by Member 14184489
Hi, I have an ASP.NET Core MVC app that contains two entities: Employee and Task. The relationship between these two entities is One-to-many. The information stored for an employee is the full name, email, phone number, date of birth, and monthly...
11 Mar 2023 by OriginalGriff
The first thing to note is that that simplistic test will not work in January ... it will not roll back to December! Have a look at this: DateTime.AddMonths(Int32) Method (System) | Microsoft Learn[^] and think about what you actually need to...
8 Mar 2023 by Paul Maxwell 2023
I have looked briefly at the code image you provided and didn't see any JavaScript, so I'm not sure if this suggestion will make sense. However, it is a common technique to use JavaScript to test form input. This small JS function isMoney uses...
8 Mar 2023 by Keshav Mooruth
I am working on a C# E-Commerce application. I having difficulties deleting and adding a item to the cart. It gives me the error in the price column which is a decimal field. The application only executes the delete/add to cart when I change...
2 Mar 2023 by eekayonline
Based on the error message you provided, it appears that the issue may not necessarily be related to the tag in your web.config file, but rather to the Request.Anonymous field being null. Here are a few things you can try to troubleshoot the...
2 Mar 2023 by Uwakpeter
I am trying to authenticate Anonymously in my mvc 5 project, it seems to work fine in my local host, but after deploying to production server, it does not see see the anonymous authentication tag in web.config file, i am having this error: Object reference not set to instance of an object,...
23 Feb 2023 by Hania Anum
Hello Guys I am quite new to linq and .net core. I am trying to calculate the next tax return date of a company as a part of my final year’s project. If there is a newly made company with no tax has been made yet (means no entry in the tax...
16 Feb 2023 by Dave Kreskowiak
Ignore me as I need to brush up on my EF Core.
15 Feb 2023 by Shwetabb
For below query, resulting sql query has some joins missing: var query = this.practicesDbContext.ServiceTransactionToClaims .Include(x => x.ClaimEntity) .ThenInclude(x => x.Carrier) .Include(x => x.ServiceTransaction)...
15 Feb 2023 by Kenji Elzerman
Learn the basics of Entity Framework with the database-first approach
9 Feb 2023 by Member 13220552
hello, i use asp.net core for my app. i have installed identity server 4 when i launch my API it work well, but when i lauch my front end i have this error Sorry, there was an error : unauthorized_client Invalid redirect_uri Request Id:...
9 Feb 2023 by Erik Sattler
Try with HTTPS Was the problem in my case :-)
6 Feb 2023 by JBartlau
This article provides an overview of Visual Studio's integration of combit's report generator List & Label.
6 Feb 2023 by Max Speed 2022
hi,i joined 2x tables together and bound the items to my datagrideview(membersdataGrid),and thats worked but i can't reach id or anything else in my datagrid here is my code private void Load() { var st = (from s in...
6 Feb 2023 by Richard Deeming
You've created an anonymous type[^] to represent the projection. There is generally no way to cast that to an object and read its properties short of reflection. One simple but fragile approach would be to use C#'s dynamic type[^], which will...
26 Jan 2023 by Davy Quyo
Hello I have an entity which has a string id. The is is autogenerated by a function into the database. I'm using the nugget package entityframeworkcore.sqlserver version 7.2 to store my entity into my database but somehow things don't work as...
26 Jan 2023 by Graeme_Grant
Here is a good Google Search: entity framework tutorials - Google Search[^] This one, in the search results, I used a bit when needed: Entity Framework Tutorial[^]
17 Dec 2022 by Kenji Elzerman
Let's take a look at the very fundamentals of LINQ and how to use it.
7 Dec 2022 by Randomuser787
I'm working in mvc 5 entity framework SO im having 3 filters in index view with foreach loop getting items from database and displaying through viewbags to checkbox. After selecting check box and submitting i couldn't keep the selected items...
5 Dec 2022 by Kenji Elzerman
Fundamentals of Entity Framework
26 Nov 2022 by Rudi Breedenraedt
How to share a transaction across multiple Entity Framework contexts
24 Nov 2022 by Member 15825061
I have a code block that works just fine, but it is troubling me by looking at it, there has to be a more simplified way, or cleaner way, to get the count of records in a database. I want to build a dashboard with about 10 record sums and I...
24 Nov 2022 by Richard Deeming
If you just need to count the records rather than loading them: int count = await _context.Blog.CountAsync(); EntityFrameworkQueryableExtensions.CountAsync Method (Microsoft.EntityFrameworkCore) | Microsoft Learn[^] That method has been...
24 Nov 2022 by Member 15825061
EF 6.0.10 is current version used var count = _context.Blog.FromSqlRaw($"SELECT COUNT(bId) FROM Blog").ToList(); ViewData["BlogCount"] = blogCount.ToString(); The sql works fine when I run query in SSMS, but I am getting an...
24 Nov 2022 by Dave Kreskowiak
Your query is telling EF to get all of the records from the Blog table, not count them. That's what the .ToListAsync call is doing. You didn't say which version of EF you're using, so this is just one possibility. If you want just the count, you...
15 Nov 2022 by Richard Deeming
You haven't shown any code, nor explained what the problem is. Based on the vague description provided, you need: Grand Total : @(Model.Sum(c => c.Price) + 100) But this sort of code really belongs in the view-model, not the view...
15 Nov 2022 by Keshav Mooruth
I am working on a C# E-Commerce application. I want to add 100 to the calculated grand total value in the front end Cart.cshtml File. What can I add this value in the Cart.cshtml file? https://i.stack.imgur.com/L0vMe.png[^] ...
13 Nov 2022 by Keshav Mooruth
I am working on a C# E-Commerce application. I having difficulties deleting and adding a item to the cart. It gives me the error in the price column which is a decimal field. The application only executes the delete/add to cart when I change...
13 Nov 2022 by Keshav Mooruth
I am working on a C# E-commerce Application. After I add two products to my shopping cart, I get Multiple Endpoints error when attempting to delete from the cart. How can I successfully delete these items? Please view the two images attached...
13 Nov 2022 by Graeme_Grant
The error message is very clear, you have 2 endpoints with different names but with the same method signature. To quote AmbiguousMatchException Class (System.Reflection) | Microsoft Learn[^] An AmbiguousMatchException is thrown when a member...
9 Nov 2022 by ahmed_sa
I work on .net core 6 vs 2022 i see function have telement but i don't know what this mean can you show me please ? and when use it are there are any thing best from using telement What I have tried: public List...
9 Nov 2022 by OriginalGriff
It's not telement, it's TElement: it's a type placeholder that makes the method work with multiple types without you having to code for all of them separately. Generic classes and methods | Microsoft Learn[^] Get used to them, they are a very...
8 Nov 2022 by Keshav Mooruth
I am working on a E-Commerce application in C#. I am following this tutorial on Youtube: https://www.youtube.com/watch?v=R25Edio81AU. When I do Migrations for each of the Tables in the ApplicationDBContext, the Migrations are empty. When I...
8 Nov 2022 by Richard Deeming
Deleting the migration files won't be enough. You also need to delete the "model snapshot" that's used to compute the difference between the last migration generated and the current model. The simplest option would probably be to delete the...
30 Oct 2022 by ahmed_sa
I work on entity framework on web application i get error when get connection string connection string as below : metadata=res://*/ERPEntities.csdl|res://*/ERPEntities.ssdl|res://*/ERPEntities.msl;provider=System.Data.SqlClient;provider...
30 Oct 2022 by Richard Deeming
You're passing an Entity Framework connection string to a class which expects a SQL Server connection string. You need to extract the SQL Server connection string and pass that in instead. For example: .net - Extract connection string from an...
28 Oct 2022 by Member 14108019
I am trying to save data into the MS SQL db using Entity Framework in dot net core. But I am getting this error - "The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception...
29 Sep 2022 by Mitchell CSharp
Issues like: Could not load information for project could not load file or assembly What I have tried: Updating Microsoft.VisualStudio.Web.CodeGeneration.Design version 6.0.9 to 6.0.10, but when scaffolding it keeps going back to version...
20 Sep 2022 by Achraf Dahdah
Introducing FOREIGN KEY constraint 'FK_books_subCategories_SubCategoryId' on table 'books' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create...
20 Sep 2022 by Richard Deeming
As the error says, you have introduced multiple cascade-delete paths between categories and books: when you delete a category, you have to delete all books in that category, but you also have to delete all sub-categories in that category, which...
15 Sep 2022 by swathi p 2022
i am getting below issue when i ran scheduler in server. but when i run same scheduler in different server it worked.. Not sure why its giving below error only in one server. Can anyone please help.
3 Sep 2022 by TimWallace
You can use the TDE feature baked in to SQL Server. Check out Microsoft 's how-to: Transparent data encryption (TDE) - SQL Server | Microsoft Docs[^]
29 Aug 2022 by Jamie888
Hi, I have 2 simple LINQ codes written in VB NET below. Which are to select record from database table. From the below 2 statements, they are almost identical, just the second query has one more condition in WHERE clause. Dim queryOne = (From...
25 Aug 2022 by Randomuser787
I have created session and also tables in db i just wanna store who creates or manipulates the data when a user logged in. when a user exists then from the log in -session it takes username and should store in the table at createdby how can i...
23 Aug 2022 by CIDEY
I would like to make it so that when you double-click on a cell, the program defines an instance of the class and changes its attribute in the database, after which a request is sent to the server every 5 seconds, and the selected object will go...
15 Aug 2022 by DiponRoy
How to delete all rows in EF Core 6 using alternate options
9 Aug 2022 by DiponRoy
Run Raw SQL Query - Entity Framework Core 6
7 Aug 2022 by DiponRoy
EF Core first publishing multiple DB contexts in same DB
3 Aug 2022 by DiponRoy
Options to customize EF Core migration table
31 Jul 2022 by ahmed_sa
==========Problem========== Cannot add functions to Next previous last first for create action using repository pattern based on EmployeeId field ==========Example========== Employee Id : 5 as last record IF create action view get loaded it must show max+1 for Employee Id meaning it will...
13 Jul 2022 by jbravofaria
Hello all, I've an application that uses Entity Framework 6.0 for SQL Server Data Access. I need to start using encryption for data at rest and data transactions. Can this be achieved? Any tutorial or instructions about how to do it? Thanks in...
29 Jun 2022 by Vikas Goswami0297
Unable to create migration in visual studio 2022 command : add-migration init Error : Unable to create an object of type 'EmployeeContext'. For the different patterns supported at design time What I have tried: PM> add-migration init Error...