Questions tagged [ef-core-2.1]
If you have questions regarding the 2.1 version of Entity Framework for .NET Core.
498
questions
0
votes
0
answers
13
views
Alternative for filter include ef core v2.1.11
I'm trying to optimize a code and I've come up with filter include and only to discover that this is not possible with the current version.
The code/query that I'm trying to optimize is this:
var ...
0
votes
3
answers
385
views
LINQ query join to get entries for left table where right table has no matching records
So the equivalent of this query:
select * from car
left join parts ON car.Id = parts.carId
where parts.MemberId = 1
is this, in EntityFrameworkCore LINQ , using an IQueryable which has already ...
0
votes
2
answers
476
views
EFCore join values
I'm trying to join a big table to a small list of data pairs using EFCore 2.1.1. I want this join to happen server-side, rather than trying to download the whole table, e.g translating to something ...
1
vote
1
answer
228
views
using same delegate in LINQ Where(x => f(x) > y) and OrderBy(f) with SQL compilation [duplicate]
I'm attempting to write a relatively simple but general pagination function for EFCore, and am having trouble finding the right function type to make sure that my sort-key selector is translated to ...
0
votes
0
answers
182
views
While updating parent entity, EF Core is deleting child entities
I recently updated my project from ASP.NET Core 2.1 to 5.0, EF Core is removing the child entities once I try to update the parent entity.
Profiler response, when project project was running on ASP....
0
votes
1
answer
83
views
How can i use Linq expression for Join on multiple table in EF Core 3.1
I have the following 5 models. I want to join and group them with LINQ in my ASP Core API Application.
I want to join all my JournalVoucher,PurchaseInvoice and SaleInvoice to calculate Item Input And ...
1
vote
1
answer
950
views
How can I optimize slow (not-so) complex queries in Entity Framework Core 2.1
I have a LINQ query that makes string search within a few tables. The query however is painfully slow on big tables. At my first attempt, I was getting a timeout. I was able to improve the performance ...
0
votes
0
answers
412
views
How to ignore ISoftDelete interface behavior for the related entities queries using EF Core and ABP?
I'm using EF Core and ISoftDelete of ABP for some entities. The global version of aspnetcore and EF Core is 2.1. ABP is 3.4.0
For each query to the database (for the ISoftDelete entity) that is not ...
0
votes
1
answer
83
views
EF Core | Need to use Navigation property for update on one property, but not another (Modules) [duplicate]
I have a file table where I am adding a FK to a module table to add in which module it is coming from.
When we create the record into FileSystemItems, we need to also update FileSystemItemsDatas as ...
0
votes
3
answers
146
views
Retrieve nullable object using EF CORE
I am a beginner, and while testing some code, I can't seem to understand how to do this properly..
1st: I have a City class:
public class City
{
public City()
{
ZipCode = "";
...
0
votes
2
answers
844
views
Entity Framework Core 3, Define DBSet for query but dont create migration entry
Within EF core 3.1, I am trying to run some custom SQL as a test, to see if I can populate a custom object. My custom object is called CustomPerson.
public partial class CustomPerson
{
public ...
1
vote
0
answers
225
views
Is it possible to combine multiple IQueryable into a single one without using Union?
Good evening. Is it possible to combine multiple IQueryable into a single one without using Union in EF Core 2? The main problem is that it doesn't allow to use methods like .Union(), .Except() etc.
...
-2
votes
1
answer
114
views
EF Core with AutoMapper
I have a DTO containing properties and a Model, eg student can have more than one module and a module can be associated with more than one student. the properties are mapping fine but the Model doesn'...
0
votes
0
answers
363
views
EF core error showing up randomly "The column 'Id' was specified multiple times for 't'.\r\n"
I have this linq query which works perfectly fine but sometimes it throws exception, following is start :
query = table.Include(x=>x.table2)
after applying few conditions in code finally ...
0
votes
0
answers
458
views
EFCore 2.1 and Pomelo MySql - Left Join LINQ Query Not working
I have two tables with the following relationship: "Order" having one to many relationship with "OrderTasks"
I am trying to run the following SQL statement through LINQ:
SELECT o.*
FROM `...
-1
votes
1
answer
929
views
Different datetime format returns wrong result set in EF Core and LINQ. DateTime.ParseExact does not work
I have an ASP.NET Core MVC application with the culture set to en-GB using a date time format of dd/mm/yyyy.
I am using:
.NET Core 2.1
EF Core 2.2
SQL Server 2019 (v15)
The date column is of type ...
4
votes
1
answer
358
views
How to debug Expression.Lambda? (Difference in Expressions tree evaluation between .net core 2.1 and .net core 3.1)
I've created a small program that shows some differences between .net core 2.1 and 3.1:
using System;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query;
public class Program
{
...
1
vote
4
answers
4k
views
EF Core 2.1 - No database provider has been configured for this DbContext
I have ASP.Net Core 2.1 with EF Core 2.1. This is how my DbContext class looks like
app.DAL.EF -> Layer
using app.domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore....
0
votes
1
answer
119
views
EF Core 2.1 - Handling connection on parallel async methods
I have multiple async methods in my DbContext to call stored procedures. All those methods handle connections as below.
DbConnection connection = this.Database.GetDbConnection();
bool ...
2
votes
0
answers
73
views
EF Core 2.1 foreign key with different datatype
I have thes model classes:
public partial class InventoryCustomer : EntityBase, ICrudEntity<int>
{
public int Id { get; set; }
public int? SlsalesLevelTypeId { get; set; }
public ...
5
votes
2
answers
3k
views
EF Core power tools generate nullable Boolean
I am using EF Core Power Tools version 2.4.0 with Miccrosoft.EntifyFrameworkCore.SqlServer version 2.2.6
I have SQL table column IsActive defined as [IsActive] [bit] NOT NULL
I use EF Core Power Tool'...
0
votes
0
answers
204
views
Create User schema(s) level in SQL Server
I am at a very Green level in the SQL world.
I have a registration page in my application. This form asks for a couple of fields
Username
Schema names (checkboxes)
Now on the submit button of this ...
4
votes
2
answers
3k
views
How to define schema table level
I am using EF Core 2.1 with C# for my application.
For some reason, there are a few tables for which I want the schema to be dbo while for others app
public class MyAppContext : DbContext
{
...
0
votes
2
answers
99
views
Dotnet EF Core 2.1 throws QueryClientEvaluationWarning when querying decimal property
I have a C# class Loan that is mapped to a Loans table in a SQL Server database. I am using DotNet EF Core 2.1. to interact with the database from my code.
public class Loan
{
public ...
0
votes
1
answer
518
views
How to retain data gained from multiple requests in EF Core?
I have asp.net core web api with React client. I'm adding data through my user interface created in React. In my api, Db context is added as scoped service, and each time my request finishes and new ...
0
votes
1
answer
2k
views
Returning Null for the Related Entity [duplicate]
I am using EF core 2.1.14
Here is my Class for DbContext which I have created by scaffolding:
public partial class AgriDbContext : DbContext
{
public AgriDbContext()
{
}
public ...
3
votes
2
answers
3k
views
More than twenty 'IServiceProvider' instances have been created for internal use by Entity Framework
I am getting this warning in my ASP.NET Core 2.2 application
warn: Microsoft.EntityFrameworkCore.Infrastructure[10402]
More than twenty 'IServiceProvider' instances have been created for internal use ...
2
votes
1
answer
7k
views
EF Core: How to query a SQL View
I have a SQL View in my DB called 'dbo.Viewtest'. This view combines the data of 2 other tables, that have identical column types. The view also adds a column to show from which table the data ...
0
votes
1
answer
975
views
Using ExecuteInTransaction with UserManager
We are implementing EnableRetryOnFailure but as discussed on https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency, this does not work out of the box for user defined ...
4
votes
1
answer
2k
views
Scaffold dbcontext of specific table from oracle database throws error unrelated to that table
I am trying to scaffoled the db context of one specific table in an existing oracle db.
dotnet ef dbcontext scaffold 'data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=some.remote.hostname)(PORT=...
0
votes
1
answer
1k
views
Not able to install Microsoft.EntityFrameworkCore from Nuget Package Manager
I am trying to install Microsoft.EntityFrameworkCore in my ASP.NET Core Web API project. But I get an error when I try to install:
Error Package restore failed. Rolling back package changes for
...
0
votes
0
answers
77
views
EF Core 2.1 adding unwanted column to schema because of owned entity
I have an owned entity Price which is used by two other entities. When I run the schema generation script, EF is adding an additional column to one of the other parent entities. How can I get this ...
1
vote
0
answers
114
views
How can I turn a predicate expression into a SQL Where clause
I use EF Core in my application. However, I have one part of the app where I desperately need to use SQL MERGE statements. Based on a post that I saw, relating to a project called FlexLabs.Upsert, I ...
-1
votes
1
answer
137
views
ExecuteSqlCommand return -1?
I am trying to call a stored procedure from code , in ef core 2 i found that i can use context.database.ExecuteSqlCommand() function to execute any stored procedure in my database.
While the stored ...
0
votes
0
answers
745
views
Why EFcore PropertyEntry 'IsModified' useless
I am trying to update an entity by efcore 2.1.1
I don't want update two cols : "CreatedAt","CreatedBy"
so I write a virtual function , I set column 'CreatedAt' a value, and then I exec my function to ...
0
votes
1
answer
308
views
Execute sql command after opening connection and before closing
Given: ASP.NET Core 2.1 WebApi, EF Core 2.1, SQL Server 2008 R2 legacy database.
Question: What`s the best way to execute sql command "EXECUTE AS " right after every connection opening and "REVERT" ...
1
vote
4
answers
1k
views
Entity Framework Core 2 Owned Entity Types - Change Names of Table Columns
I have entity classes, something like this:
public class Bike
{
public int Id { get; set; }
public int ModelId { get; set; }
public Model Model { get; set; }
public Contact Contact ...
2
votes
1
answer
679
views
Entity Framework Core 2 with DBQuery - Get Object reference not set to an instance of an object
I'm using Entity Framework Core 2 and tried BDQuery. When I try to map the result of a FromSql() request in a Select, I get an error:
Object reference not set to an instance of an object.
Here is ...
2
votes
1
answer
1k
views
EF Core, DI, Repository pattern and issue with base repository structure
I have .net core rest api, which contains hybrid structure in which it only contains repositories and not the service layer.
Now, there is one issue that I am facing with base repository and main ...
0
votes
1
answer
323
views
Creating DbCommand does get timeout assigned from DBContext
I have ASP.NET Core 2.2 application using EF Core. In startup.cs i am setting CommandTimeout to 60 seconds
services.AddDbContext<CrowdReason.WMP.Data.Entities.WMPContext>(options =>
...
1
vote
1
answer
71
views
Why does EF Core 2.1 only add 1 index for 2 FKs?
I use SQL Server 2017 (v14.0.2027.2) and EF Core 2.1.
After I added migration on this code:
public class TblTrack
{
public long Id { get; set; }
...
}
public class TblProduct
{
public ...
1
vote
0
answers
132
views
Avoiding Orphaned Records in Entity Framework Code First
I'm finding a lot of records in our databases with EF Relationship keys that are nulled out (making them orphaned records and useless to us).
For example, if I have an Item that owns a list of ...
0
votes
3
answers
1k
views
How to avoid redundancy/save data in EF Core many-to-many relationships?
Can someone please answer me how to properly add and insert data into a join table/many-to-many relationship with Entity Framework Core, without saving data multiple times?
My Database Context looks ...
5
votes
0
answers
82
views
Why temp tables are being created automatically in database
I am using Entity Framework Core 2.1 with .NET Core 2.0. I am using code first approach. I am seeing sometime temp tables are getting created in the database.
Here is the screenshot of the problem.
...
0
votes
0
answers
37
views
EF core- view queries of lazy loading
We are using asp.net core 2.1 and EF core 2.1.
We are currently using lazy loading in EF core and we have noticed that some of our server requests take now way too much time to run.
Is there a way ...
2
votes
1
answer
765
views
How to find the first parent in a tree-like hierarchy using LINQ with EF Core
I have two entities:
public class Child
{
[Key]
public string Id { get; set; }
public List<Parent> Parents { get; set; }
}
public class Parent
{
[Key]
public string Id { ...
0
votes
1
answer
1k
views
EFCore Linq Cannot perform an aggregate function on an expression containing an aggregate or a subquery
I have a EFCore linq query that i try to get a sum of units, but i am getting an exception thrown.
so here is the structure.
var query = _jobRepository.Table;
i am doing some filtering, nothing ...
0
votes
0
answers
233
views
Postgres keyword DEFAULT is not recognised as column value in EF core?
I am getting a very strange error when I insert a record into my postgres database using EF core. The library I'm using is Npgsql.EntityFrameworkCore.PostgreSQL.
Here is my data model, the Category ...
11
votes
3
answers
14k
views
EF Core 3 x.Contains() in expression where x is ICollection
I've got the following data layer setup:
public class Repository : IRepository {
private readonly MyDbContext _dbContext;
public List<Meter> Search(Expression<Func<Meter,...
0
votes
1
answer
396
views
How to avoid multiple db calls for inserting an object with related entities in EF Core
I have a table say Transactions that has two foreign keys. One foreign key references Customers Table and the other to BillAmount Table. So my POCO is like
public class Transaction
{
public ...