Questions tagged [ef-core-3.1]

Use this tag for version specific questions about the 3.1 version of Entity Framework for .NET Core. When using this tag also include the more generic [entity-framework-core] tag where possible.

698 questions
-1
votes
0 answers

How to use EF Core and LINQ query syntax to get entities and counts of their children

How would I use EF Core and LINQ query syntax to select entities and counts of their children. For example, select all Teams and a count of each team's Players. Note: the Team entity does not have a Players navigation property collection on it. The…
NSouth
  • 4,477
  • 7
  • 38
  • 71
-1
votes
1 answer

updating child entity in parent entity gives duplicate violation key error

I have below classes spacetype and mastersection which is having below structure public class SpaceType { public Guid Id { get; set; } [ForeignKey("MasterSection")] public string MasterSectionName { get; set; } public virtual…
Enigma State
  • 16,494
  • 25
  • 86
  • 179
-1
votes
1 answer

How do I save data from xml file in related tables using ef core?

I am creating the associated table like in the photos below. How do I save data in my related tables via XML?
-1
votes
1 answer

Unable to check if a list of int is completely contained in another int list

I have a list of int that represents service ids. and I want to make sure that all of those ids exist in the database. In other words , I want to scan the list of ids and the table of services to make sure that all of these ids exist in the…
Ataa Aub
  • 55
  • 8
-1
votes
1 answer

Automapper.ProjectTo() is throwing null reference exception

I Have the following mapping : CreateMap() .ForMember(des => des.Code, src => src.MapFrom(s => s.Code)) .ForMember(des => des.Notes, src => src.MapFrom(s => s.FormNotes)) //other…
-1
votes
1 answer

TypeLoadException when injecting Context in Worker

I currently have a Razor page application (Core 3.1) connected to a SQL Database with a Context using IdentityDbContext. When trying to use this same context in my Worker Service, I continue to get this error: System.TypeLoadException: 'Method…
Andy Xufuris
  • 658
  • 2
  • 9
  • 30
-1
votes
1 answer

Order results by the length of varchar/nvarchar column value in EF Core

How can I order the results set by the length of column value in EF Core? One of the entity properties is barcode, which I need to bring entities with shorter barcodes on top of the list while searching the value likeliness not exact match. In SQL…
Mkhairy
  • 137
  • 2
  • 9
-1
votes
2 answers

How to add translations to database after API response with EF Core?

I have a requirement to add a project and translate its description with an external API translation service into several languages (so they exist in the database and it's possible to fetch a project in different languages later). Since translation…
-1
votes
1 answer

How to sort on DB side, if entities are not connected via Navigation (since it's not possible)

I want to have my EfCore query translated into the following SQL query: select c.blablabla from codes c left join lookups l on c.codeId = l.entityid and l.languageCode = and l.lookuptype =…
Alexander
  • 739
  • 11
  • 15
-1
votes
1 answer

How to efficiently filter children based on parent's attribute

I am looking for help with building a search bar. I have 3 database tables here: Case -> Exhibit -> Tasking. Case is Exhibit's parent and Exhibit is Tasking's parent. I have a table displaying info on a list of Taskings as well as their parent Id…
He Chuan
  • 21
  • 6
-1
votes
1 answer

Entity Framework "Include" does not load entity related tables

I have a project with ASP.NET Core 3.1 using Visual Studio 2019 (64 bit) and SQL Server 2019. When I run the backend it generates an error when I use Entity Framework's .Include to load data from a related table. It's strange that the same code…
DigitalDevGuy
  • 43
  • 1
  • 10
-1
votes
2 answers

Setting properties using asp-for in MVC Core App with EF Core?

As I understand it from these docs: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro?view=aspnetcore-3.1 , asp-for is used to transfer values from input elements to backend C# class properties, for example:
-1
votes
1 answer

How to Convert XML output from Stored Procedure to C# object in Asp Net Core

SET ANSI_NULLS ON; GO SET QUOTED_IDENTIFIER ON; GO ALTER PROC [dbo].[getStateWiseCompanyDetails] AS BEGIN With Data AS (SELECT Companies.RegionId, Companies.Code, Companies.CompanyName, …
-1
votes
1 answer

How many times to call .SaveChangesAsync() in .BeginTransaction() EF Core 3.1

Call SaveChangesAsync every changes like .Remove, .Update or .Add using (var transaction = _unitOfWork.BeginTransaction()) { try { var structureProfile = await…
Marco Torrecampo
  • 143
  • 1
  • 10
-1
votes
1 answer

Expression of type 'System.Linq.IOrderedQueryable`1[Models.Option]' cannot be used for return type 'System.Linq.IOrderedEnumerable`1[Models.Option]

In the following Query, I want to Sort the Children List of a Parent based on Index Property, which I encounter with the following error ... How to Fix it ? Expression of type 'System.Linq.IOrderedQueryable`1[Models.Option]' cannot be used for…
1 2 3
46
47