Click here to Skip to main content
15,891,718 members
Everything / EF Core

EF Core

EF-Core

Great Reads

by DaveDavidson
In this article, I show LINQ to Entities syntax that will produce queries with CROSS APPLY and LEFT OUTER JOIN clauses.
by Ken Haggerty
Scaffold and modify Identity in the new ASP.NET Core 2.2 Razor pages template
by Coding Notes
An introduction to ASP.NET Core MVC

Latest Articles

by Mark Pelf
Overview of new changes to EF8 – support for Row SQL returning Non-entities.
by David_Cui
To introduce a free library to save some tedious work for writing mapping code between entities and DTOs
by towaso
A short example on how to create a hierarchical web checklist
by DiponRoy
How to delete all rows in EF Core 6 using alternate options

All Articles

Sort by Title

EF Core 

9 Mar 2022 by Coding Notes
An introduction to ASP.NET Core MVC
5 Apr 2022 by Coding Notes
An introduction to ASP.NET Core MVC
18 Sep 2022 by towaso
A short example on how to create a hierarchical web checklist
21 Jul 2021 by Jeremy Likness
This article walks you through my project Planetary Docs, a repository that showcases a full application that supports Create, Read, Update, and Delete operations (CRUD) using Blazor (Server), Entity Framework Core and Azure Cosmos DB.
31 Jul 2018 by ParsleySage
EF Core 2.1 (using Razor Pages) I have a table, model and Razor Crud Pages to create new Examination schedules. The db table and model has a foreign key ID to an Examination Dates table and model, which in turn contains key dates that require adding/updating to an Exam schedule at various...
31 Jul 2018 by Mike V Baker
1) This isn't going to be specific to your situation because you're not posting any code so I can't see into your data model. But if you're using EF then you don't have to worry about the primary key foreign key values because that's entity framework's job. Your DBContext will have a data...
31 Jan 2018 by Pawel idzikowski
How to replace the web API request query string to provide case insensitive OData search
22 Jun 2017 by Kurt Swendson
How to make the migrations to change data type
1 May 2017 by Roshan Choudhary
Handling data concurrency in Entity Framework 6 with Database First Approach.
3 Aug 2022 by DiponRoy
Options to customize EF Core migration table
15 Aug 2022 by DiponRoy
How to delete all rows in EF Core 6 using alternate options
25 Nov 2020 by csrss
Hi. I am trying for a couple of days now and just cannot make it work. It seems like pretty obvious task, however. public class UserRole : IdentityUserRole { public virtual User User { get; set; } public virtual...
28 Feb 2022 by Richard Deeming
EF Core methods to call SQL Server's TRY_PARSE function
31 Aug 2021 by Member 14637786
Hello, is this possible to write SQL-translatable query to order by a dictionary table? For instance: class Customer { string Name {get;set;} IEnumerable CustomProps {get;set;} } class CustomProperty { string Name...
31 Aug 2021 by Richard Deeming
Try: .OrderBy(x => x.CustomProps.Where(p => p.Name == "Color").Select(p => p.Value).FirstOrDefault()) Or: .OrderBy(x => x.CustomProps.Where(p => p.Name == "Color").Select(p => p.Value).Min())
10 Jul 2021 by Manos Kanellopoulos
Im using DDD in my project and I have an entity which belong to two bounded contexts with different properties each one. Both bounded contexts add records by this entity. How can I configure these two classes to map to same table by fluent Api? ...
10 Jul 2021 by #realJSOP
Try using the mapped entity as a base class for two derived entities.
3 Jun 2018 by saadishahin
A quick psedu-code for EF Core that's equivalent to modelBuilder.Configurations.AddFromAssembly in entity framework
16 May 2022 by Mahfoud Bouabdallah 2022
I started creating a role-based security system in my WinForm application so I began with Form navigation (Permission Navigation) and this is my entity's public partial class User { public User() { UsersToRoles = new...
16 May 2022 by Mahfoud Bouabdallah 2022
I decided to go this way: When the user has successfully logged in, I catch the Id then I make a call to get all roles related to that user after that I make another call to get all permission navigation using role Id that I got earlier.
2 Jun 2021 by csrss
Hi. I am trying to understand this method for a whole day long now now. I need to call a stored procedure, which does not return, or at least does not suppose to return anything. Just like a void method call. However, no matter what I am trying...
2 Jun 2021 by Gerry Schmitz
Your query has nothing to do with EF; there is no relation between it and any EF entities; it's a simple C# SQL SP call. (If MyClassSet had elements, it might work, but that's only because you made your query dependent on it) sql server - How to...
2 Jun 2021 by Richard Deeming
If you don't want to return any results, don't use FromSqlRaw on a DbSet; use the ExecuteSql* extension methods on the Database façade. int returnValue = context.Database.ExecuteSqlRaw("EXEC procedure_name;"); ...
29 May 2023 by hardover
Basic situation is: Application manages a standard set of records for an organization. It will work on only one organization at a time. App must be able to create a new organization on request. App should be able to create a database for a...
29 May 2023 by Graeme_Grant
What you are trying to achieve is multi-tenancy. Here is a google search that will point you in the right direction: ef core multi-tenancy - Google Search[^]. First link returned: Multi-tenancy - EF Core | Microsoft Learn[^]
14 Nov 2020 by csrss
Hello everyone. This is my Entity, which is stored in database: public class Rule { [Key] public int ruleId { get; set; } public string name { get; set; } public int[] categoryIds { get; set; } } I...
14 Nov 2020 by Gerry Schmitz
If you need a "string" to act like a "list", just add another Getter; EF / LINQ doesn't care. public string Categories {get;set;} = "1;2;3"; public ICollection CatList {get{return this.Categories.Split(';').ToList();}}
3 Dec 2020 by csrss
There are 2 tables: public class Info { [Key] public int id { get; set; } public int name { get; set; } public int surname { get; set; } } public class Client { [Key] public...
3 Dec 2020 by Richard Deeming
Cascade Delete - EF Core | Microsoft Docs[^] Assuming this is a one-to-one relationship[^]: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasOne(c => c.info) .WithOne(i...
1 Apr 2024 by Mark Pelf
Overview of new changes to EF8 – support for Row SQL returning Non-entities.
7 Aug 2022 by DiponRoy
EF Core first publishing multiple DB contexts in same DB
16 Feb 2019 by Ahmed Dabas
I'm working on an desktop app using (wpf , EF Core) and i note that response little bit slow in first query when application run first time , then every thing ok what is the cause of this problem? and how can i handel it ? What I have tried: i can't solve it , the problem still
16 Feb 2019 by Dave Kreskowiak
That is the "warm up time" for EF. It's doing a first connection to the database and verifying that the structure matches what it expects in order to work with your context. There is nothing you can do to "fix" that.
16 Feb 2019 by Gerry Schmitz
You run a scheduler that every morning fires off the "first query of the day" while everyone else is sleeping.
18 Nov 2018 by ahmed_sa
Problem The relationship from 'SalesFooter.SaleHeaders' to 'SalesHeader.SalesFooters' with foreign key properties {'SalesOrderNo' : int} cannot target the primary key {'SalesOrderNo' : int, 'SalesType' : int, 'SalesYear' : int, 'BranchCode' : int} because it is not compatible. Configure a...
18 Nov 2018 by Sk Imad
If you want to get relation with both class, the property name should not be same in both class.
10 Feb 2017 by PrashantRamteke
Execute stored procedure using Entity Framework Core in .NET Core Class library project
26 Feb 2019 by Golden Basim
i created this view to calculate the total stocks of every item in every store as : CREATE OR REPLACE VIEW `view_items_stocks_smallest_unit_prices_noserials` as SELECT items.stitems_ID, items.stitems_Status, items.stitems_Name, items.stitems_Type, ...
26 Feb 2019 by OriginalGriff
See here: SQL GROUP By and the "Column 'name' is invalid in the select list because..." error[^]
25 Dec 2021 by scott_liu
Entity Framework Core client evaluation was disabled by default since version 3.0 because of performance.
1 Oct 2017 by Marcelo Ricardo de Oliveira
Building a tiny e-Commerce on ASP.NET Core, Razor pages, React JS.NET and EF Core
5 Dec 2017 by Vincent Maverick Durano
This article demonstrates how to build an ASP.NET Core application using Entity Framework Core Code-First development with Web API and MVC.
10 Oct 2017 by Vincent Maverick Durano
This article is the first part of the series on Getting Started with Entity Framework Core. In this post, we will build an ASP.NET Core MVC application that performs basic data access using Entity Framework Core.
21 Jul 2021 by Jeremy Likness
In this blog post I look at what GraphQL is, share benefits and challenges, review the current .NET ecosystem, and walk you through some hands-on examples.
31 Oct 2019 by Richard MacCutchan
EF 3.0 in .Net - Google Search[^]
1 Nov 2019 by Richard Deeming
As you've discovered, you can't: Breaking changes in EF Core 3.0 - EF Core | Microsoft Docs[^]: Starting with 3.0, EF Core targets .NET Standard 2.1 and will run on all platforms that support this standard. This does not include .NET Framework.
20 Feb 2019 by avelsamy
Hi, i have created the stored procedure which returns data from multiple tables. Here i i am unable(don't know) to call the stored procedure with parameter. Can anyone please help me to resolve this. I tried with one scenario its returns Id = 18, Status = WaitingForActivation, Method =...
20 Feb 2019 by Gerry Schmitz
How to: Execute a Parameterized Stored Procedure Using EntityCommand | Microsoft Docs[^] EntityClient Provider for the Entity Framework | Microsoft Docs[^]
16 Jul 2020 by Torakami
The problem is that, in the group by I want the first result in the group by using first() or firstOrDefault() but I get an error saying Quote: could not be translated. Either rewrite the query in a form that can be translated, or switch to...
16 Jul 2020 by Richard Deeming
EF Core's GroupBy support can be a bit flaky. Try starting the query with the users instead: var skipperLocations = _appContext.Users .Select(u => u.Locations .Where(l => l.Timestamp > cutOffDate) .OrderByDescending(l =>...
7 Apr 2021 by nrramesh
select * from Table where CAST(FORMAT(column,'00.00') as varchar(20)) LIKE '%03.1%' Now, I have a IQueryable and want to send the Query through LINQ with the given format What I have tried: obj.Number.ToString("{0:0.00}")
7 Apr 2021 by Richard Deeming
Define the function(s) you want to call: public static class SqlFunctions { public static string Format(decimal? value, string format) => value?.ToString(format) ?? string.Empty; public static void Register(ModelBuilder...
14 Jun 2022 by Anvarkhon Khamzaev
There are two entities Task and User. Task entity has two foreign keys (both int - id) Performer and Creator that is linked to User entity Id field. They are shadow properties, so in db their name are PerformerId and CreatorId. When I try to test...
22 Oct 2023 by David_Cui
To introduce a free library to save some tedious work for writing mapping code between entities and DTOs
18 Apr 2023 by xTMx9
Hello, I am currently facing an error when running a method that could be related to 2 connectoin instances running at the same time but I can't find how is it happening exactly. The error: InvalidOperationException: Cannot use multiple context...
18 Apr 2023 by Richard Deeming
Quote: I have checked the program.cs file and all services are registered as "Transient" in it. Well, there's your problem. Services registered as "transient" will have a new instance created every time they are resolved. You have two (or...
9 Aug 2022 by Difameg Network Nigeria
Hi, I am working on a simple student result. I want to achieve student Positions per class. // I have this two models public class StudentData { [Key] public int Id { get; set; } [Display(Name = "StudentClass")] ...
9 Aug 2022 by Richard Deeming
Your ViewResult class represents the data for a single student. Your foreach loop would overwrite the properties of that class with the values for the last student returned. That is, it would do that, if your code compiled. But your code won't...
1 Aug 2022 by Code4Ever
I use the following code to get paged data to the DataGerid: using (var _sqliteContext = new SQLiteContext()) { AssociatedObject.LoadDynamicItems(e.StartIndex, await _sqliteContext.Equipments ...
29 Jul 2022 by Gerry Schmitz
If you want to display the last page, retrieve the last page: .TakeLast( e.PageSize ); Enumerable.TakeLast(IEnumerable, Int32) Method (System.Linq) | Microsoft Docs[^]
1 Aug 2022 by Richard Deeming
You can't "reverse the order" of that data source, because you haven't defined any order for it. The data will be returned in whatever order the SQL engine chooses to load it. Whilst that might appear to be stable at the moment, it can and will...
21 Jan 2021 by Christian Graus
No one can give you a definite answer because your question is vague. What is the task? You need to break the task into atomic parts so different threads can work in isolation
9 Jul 2023 by Graeme_Grant
Already answered here: How to store data on ASP.NET razor page using hidden field?[^]
9 Jul 2023 by ahmed_sa
I work on razor asp.net core . I face issue i can't store selected value id and selected text of select option drop down on hidden fields so I need to create two hidden fields first hidden field to store selected value id and second for store...
31 Jan 2020 by ElenaRez
I’m implementing a project using asp.net core and I'm new in this field. Employing DB first approach and creating models in Visual studio, in SQl server I have two tables called API and Applicant that have many to many relationship and there is also their junction table called ApiApplicant....
31 Jan 2020 by Bertha Wwallace
var dbContext = new MyEntitiesDbContext(); var theApiapplicant = dbContext.Apiapplicants.Where(a => a.Id == myApiapplicantId).FirstOrDefault(); theApiapplicant.IsDeleted = true; dbContext.SaveChanges(); Have fun!
8 Jun 2023 by Mahfoud Bouabdallah 2022
I have three class GdsReceptionBlackProduct, Employee and Customer public partial class GdsReceptionBlackProduct { public int Id { get; set; } public string? CreatedBy { get; set; } public virtual Employee?...
8 Jun 2023 by Richard Deeming
You have a combination of two settings which are causing this: entity.Navigation(e => e.Country).AutoInclude(); This causes the Country navigation property to always be included in any query that loads a Customer. ...
22 Mar 2017 by Fiyaz Hasan
Know how to use Entity Framework's new shadow property feature for easily implementing common audit fields for entities
21 Aug 2020 by Jeremy Likness
How do products like EF Core allow you to write whatever queries you like, then successfully intercept them to run SQL commands? The secret is in the provider.
10 May 2020 by Daan Acohen
The test problems you face when having a database dependency and how to resolve these problems
16 Nov 2020 by csrss
Hello friends! Here are my entities: public class Subscription { [Key] public int id { get; set; } public string name { get; set; } public double data { get; set; } } public class...
12 May 2017 by DaveDavidson
In this article, I show LINQ to Entities syntax that will produce queries with CROSS APPLY and LEFT OUTER JOIN clauses.
1 Apr 2017 by Stein The Ruler
Hi! I have two classes; Item and ItemType. Item contains ItemTypeId and ItemType contains a list over Items. But the Items list never gets populated. Its always 0. Item: public class Item { public int Id { get; set; } public string Name { get; set; } public...
1 Apr 2017 by Stein The Ruler
I must have missed the part about loading entities. I added a GetItemType method to my DbContext which loads the relational data public async Task GetItemType(ItemType.ListTypes type) { ItemType result = await this.ItemTypes.Include(i =>...
15 Jul 2020 by Member 14637786
Hello, is there a good and fast way to get a single Parent object (or its id) by condition without iterating up all the levels of self-referencing relationship? The model is for example this (pseudocode): class MyObject { bool myCondition;...
14 Jul 2020 by #realJSOP
Create a stored proc and call it from EF to populate the colle ction. Let the query in the stored proc add the necessary "relationship" columns and populate them. At that point, your child objects should have a reference to the parent. Let the...
14 Jul 2020 by Laxmidhar tatwa technologies
public class MyBuilding { public int id { get; set; } public List MyFloors { get; set; } } public class MyFloor { public int id { get; set; } public List MyOfficerooms { get; set;...
14 Jul 2020 by #realJSOP
Your model makes absolutely no sense. 0) The MyCondition property doesn't appear to have any association with the specified question. 1) The ParentID property should be called ID because it's the id of the object, not the parent object.. ...
15 Jul 2020 by Richard Deeming
Are you free to modify the table structure? If so, you might be able to use a HierarchyID column. hierarchyid (Transact-SQL) - SQL Server | Microsoft Docs[^] It's not supported natively, but there's a third-party library which adds support to EF...
7 Apr 2021 by mark_worrall
How to move Entity Framework Core v5.0 into a separate Visual Studio Project
9 Apr 2017 by NalaBI
I am trying to create a Controller for MVC5 using Entity Framework. but I keep encountering an error. 'Unable to retrieve metadata'. It also says The argument connectionString cannot be null, empty or contain White Space.What I have tried:I have tried to rebuild. Checked the...
9 Apr 2017 by NalaBI
I found the problem it was with my database tables data types.
24 Sep 2021 by Sni.DelWoods
I have a custom DateTime-Range class which is used in several models: public class Entity { //... public DateTimeRange Usage {get; set; } //.... } public class DateTimeRange { public DateTime From { get; set; } public DateTime...
24 Sep 2021 by Sni.DelWoods
Solved. The anontation does the whole job: [Owned] public class DateTimeRange { public DateTime From { get; set; } public DateTime To { get; set; } } Output datatable is as exptected: Validity_From = ... Validity_To = ... ...
23 Apr 2019 by Bohdan Stupak
I'm afraid you can't since Include loads all the data for your navigational property. If you are concerned with the amount of data loaded I would rather suggest you not to load the whole dataset in memory. Instead, apply some filtering to load only data you require. Also, consider learning about...
26 Oct 2018 by Simon_Whale
I have just started on a new project, where the database is built using code first. I have attempted to run the project for the first time and get the below Exception. I have checked that using (var serviceScope = serviceProvider.CreateScope()) { var...
22 Dec 2018 by Ken Haggerty
Scaffold and modify Identity in the new ASP.NET Core 2.2 Razor pages template
22 Dec 2018 by Ken Haggerty
Scaffold and modify Identity in the new ASP.NET Core 2.2 Razor pages template
21 Sep 2020 by Jeremy Likness
What if I could write a LINQ query on a client the same way I would on a server, and execute it remotely with minimal configuration, setup, ritual and ceremony?
12 Mar 2017 by Steve Van Lint
Hello,I created a monitor system for our cloud environments.The environments are individual sites with their own database. Since each site has several tasks running, we need to intercept when a task fails. There are other things I monitor but the idea is the same.The situation is as...
8 Mar 2017 by Dave Kreskowiak
Yeah, don't use Entity Framework. The problem with using it is that your DbContext is directly tied to the exact version of the database the context was written against. If the database schema changes, the DbContext has to change with it. This prevents you from using the same DbContext against...