11,224 questions
0
votes
1
answer
106
views
Trying to populate very similar relations through same property
I am trying to define two classes with the same collection-relation, through the same key on a third class, preferably using EF 6 code annotations.
I have three tables;
Current is a quick reference. ...
3
votes
0
answers
47
views
How can I force EF6 to create a test database from the current model, bypassing migrations?
I am setting up an automated integration test environment for a large, existing Entity Framework 6 project that uses a MySQL database.
My goal is to create a fresh, empty database schema directly from ...
2
votes
2
answers
116
views
AsNoTracking when selecting Non-Entities
Still on EF 6 "classic" (not core), when I do something like the following:
var basicPersonList = myContext.Persons
.Select(p => new PersonSimpleData
{
FamilyName = p....
-2
votes
1
answer
97
views
EF6: optional foreign key always null
I have a C# (C# 7.5) application that is using EF6.
I have a table that contains two foreign keys. Both are one:one relationships and both are required.
When I load a record from the database, the ...
1
vote
1
answer
160
views
How to prevent foreign keys to be set null after calling Remove on an Entity
I have an Order table that contains a nullable foreign key to another table called Product (each order can only map to one product). Each order will only point to one product. The relation is ...
0
votes
0
answers
65
views
C# Entity Framework COM Object accessed from Delphi Error [duplicate]
After installing Windows 11 Update 24H2, I have not been able to work with a COM Library developed with C# and accessed from Delphi. The failure occurs when I do a Where filter using a numeric ...
-1
votes
2
answers
67
views
Error CS0246 when defining a database connection
I'm using VS2022 and have an ASP.NET MVC project with Entity Framework 6. All Nuget packages are current.
I have a data connection InstrumentEntities; in the Server Explorer, I can see all the tables ...
1
vote
1
answer
98
views
How to map a parent-child relationship where the child type depends on the parent's discriminator field, with Entity Framework 6?
I need to map an existing database using Entity Framework 6 in order to read (only) data.
The model that bugs me is kind of a TPH inheritance strategy where the child type depends on a discriminator ...
1
vote
0
answers
51
views
Hangfire Autofac Job Can't Resolve DbContext: ComponentNotRegisteredException in BackgroundScope
I'm working on a .NET Framework 4.6.1 application using Autofac (5.2.0) for dependency injection and Hangfire for background jobs.
I have a service class StoreDataCleanupService that depends on an EF ...
1
vote
1
answer
62
views
ASP.NET Core Web API controller method throws 'transient failure'
Using Entity Framework 6 in an ASP.NET Core Web API.
I have the following controller:
[Route("[controller]/[action]")]
[ApiController]
public class ContactController : ControllerBase
{
...
0
votes
0
answers
102
views
Same projection mappping in IQueryable.Select but with Varied Child Collection filters in EF6
I have methods used in IQueryable.Select(...) that shares the same logic of mapping an Entity class to a DTO class, but filter the navigation properties in the projection differently. The problem is ...
0
votes
1
answer
78
views
Explicitly Loading filtered navigation property via Load() not working
I have a query that I want to return an entity with a filtered collection navigation property. According to the EF6 document I should be able to load it via explicit loading. However, after the ...
0
votes
2
answers
149
views
How to make LINQ query faster
Running NbLinksExpirationStatus takes about 12 seconds to execute, which is not fast enough for what i am trying to achieve. Could it be Contains() problem and is there any way i can make it execute ...
1
vote
1
answer
238
views
Workaround in Entity Framework 6 for keyless tables
We have a .NET Framework 4.8 application that uses Entity Framework 6.
Now we are having a problem that we need to add some tables that don't guarantee any uniqueness (no primary key and rows can ...
1
vote
0
answers
40
views
Assembly Binding Redirect handling for ef6.exe outside of Package Manager Console
I have a C# / ASP.NET MVC project using Entity Framework 6. When I am deploying database migrations by running
Update-Database -Verbose
in the Package Manager Console in Visual Studio, everything ...
-1
votes
1
answer
105
views
Entity Framework 6, cannot insert duplicate key violation on update [duplicate]
I have a table ExerciseEnvironments with a unique constraint on a foreign key ExerciseId and type id TypeId combination, where a single exercise can have multiple unique environments but not multiple ...
1
vote
1
answer
101
views
Entity Framework 6 - database-first without EDMX
We are bulding a console app that needs to read data from some views in an Oracle database, and save that data to an external system. For compatibility reason, we need to use .NET Framework 4.7.2, and ...
1
vote
0
answers
79
views
NullReferenceException when including multiple levels of classes
I have the following classes:
public class A {
public List<B> bList {get;set;}
public List<X> xList {get;set;}
}
public class X {
// data
}
public class B {
public ...
0
votes
0
answers
33
views
System.NotSupportedException: 'LINQ to Entities does not recognize the method xxx and this method cannot be translated into a store expression
One of the most common filters I apply to a query is to restruct the results to a single (business) organisation e.g. ctx.Users.Where(user => user.OrgID == orgID).
I've created the following ...
0
votes
0
answers
37
views
EF6: creating schema before InitialCreate
I need to create a schema before the first table is created because it relies on it to exist.
I have tried Add-Migration CreateSchema with and without the flag -IgnoreChanges and then replaced Up and ...
0
votes
0
answers
28
views
Separate navigation properties for distinct subtypes in TPH hierarchy
I have an Entity Framework 6 (v6.5.1) code-first model like this (type names have been changed to anonymise the code):
public abstract class Point
{
public long ID { get; set; }
public long ...
1
vote
1
answer
619
views
Why is Microsoft.Data.SqlClient throwing TypeInitializationException when loading Microsoft.Identity.Client at runtime?
I have an Entity Framework 6 model (code-first, with migrations enabled and auto-migrations disabled) in a class library that targets .NET 4.8 and .NET Standard 2.1 (AnyCPU). This is an SDK-style ....
0
votes
1
answer
51
views
EF 6 code first with X# (or C#) does not create a database
I am struggling with EF 6 (for .NET 4.x), code first and SQLite.
I am using X# instead of C# but it does only affect the syntax.
The problem is that the SQLite database with the table is not created ...
1
vote
1
answer
50
views
Entity Framework is not consistently generating the correct UPDATE statement when updating two entities
Background
I've recently inherited this ASP.NET 4.8 project. I'm implementing functionality that sets one row in the database as a default record. This is backed by a SQL Server which has an UNIQUE ...
0
votes
0
answers
37
views
Entity Framework Save data that exceeds 50kb issue
Details:
Entity Framework 6.4.4, using Owin and OData. (not sure if that helps with explaining).
Asp.net Mvc project, using .net framework 4.7.2 (limitation of legacy projects that cannot be updated ...
0
votes
1
answer
133
views
VS2017 EF6 Can not add a connection to mysql database
In VS2017 I use Microsoft EF6 to connect to a mysql database.
When I try to add a new item 'ADO.NET Entity Data Model' in my application 'APP1' there is no way to set up a connection to the mysql ...
0
votes
1
answer
49
views
Does not contain a definition for 'CreateObjectSet' and no extension method 'CreateObjectSet' in EF6
I am using Entity Framework 6 but the following code is throwing error. The code is migrated from old EF version where it is working fine.
using System.Data.Entity;
using System.Data.Entity....
1
vote
1
answer
47
views
How to ignore duplicate Breeze SaveChanges calls
I maintain a Breeze ASP.NET Web API that was initially written about 10 years ago. I didn't write it and I'm not an expert in Breeze. The client is a cellphone app developed by a third party. This ...
1
vote
0
answers
122
views
How to force Entity Framework to treat variable as constant? [duplicate]
I have an EF6 IQueryable<T> which contains a variable in a where clause. I have performance issues with parameter sniffing because the execution plans for some variable values are very ...
0
votes
0
answers
71
views
in linq'System.dateTime as DateTime(System.string) method and this method cannot be translated into a store expression
DateTime todayDateTime = P.getCurrentDateTime();
pmap_attendence customername = db.pmap_attendence
.Where(x => x.att_cust_guid.ToString() == input.cust_guid.ToString()
&& ...
0
votes
1
answer
37
views
EF6 Include not detecting foreign keys
I'm having some strange issue where I have an EDMX generated from an exisitng DB and the foreign keys are propelry captured within generated classes but upon using them with Include(), I'm getting ...
0
votes
1
answer
2k
views
Using Entity Framework Core v8.0.8 DbContext and TransactionScope to read uncommitted from a table
I'm currently looking at upgrading a .NET project (standard moving to .NET 8) that uses Entity Framework (v6.4.4) to EF Core (v8.0.8).
For the most part the experience has been painless but I have one ...
0
votes
1
answer
65
views
Entity Framework 6 change tracker issuing statements in the wrong order
Problem description
I have a method that syncs changes to graphs of entities to the database by comparing the received entities with the corresponding database rows and then updates the ChangeTracker ...
0
votes
1
answer
206
views
How to log errors in DB within a transaction that fails with Entity Framework 6
If I'm in the middle of doing a bunch of updates within a transaction, and it throws an exception, I still want to log some information in a table in the same db context so I know what happened. I ...
0
votes
1
answer
129
views
Using singleton DbContext causes connection issues in multithreaded environment
I am using SQLCipher for sqlite DB encryption in WPF application. As per knowledge they recommend to use Singleton pattern for my DbContext class ensure a single instance is used throughout my ...
1
vote
1
answer
108
views
EntityFramework Include method is not working
Spent huge of time but do not understand why .Include(t => t.Nodes) does not return any Node entities:
public class TreeRepository : ITreeRepository
{
private DataBaseContext dataBaseContext;
...
1
vote
1
answer
40
views
EF6 LINQ query for UTC database timestamps that fall on the same day as a given local timestamp?
I am trying to write an EF6 LINQ query that takes a DateTimeOffset and retrieves all database entries that have a timestamp with the same local date as the given. The database has all timestamps as ...
0
votes
0
answers
558
views
Converting an application to use Microsoft.Data.SqlClient in Entity Framework instead of System.Data.SqlClient
I've been trying to convert my application (which uses EF) from System.Data.SqlClient to Microsoft.Data.SqlClient to accommodate distributed transactions and I've hit a wall, specifically a dependency ...
1
vote
0
answers
30
views
Issue with Conditional Mapping in Abstract and Derived Classes Leading to EF6 SaveChanges Error
The OfType part of the query doesn't work as expected, and there’s an error when saving changes in the database.
Code:
using System;
using System.Data.Entity;
using System.Data.Entity....
0
votes
0
answers
45
views
Entity Framework migrations: custom initializer not applying migrations as expected
I'm working on an ASP.NET Web API 2 project, using .NET Framework 4.8 and Entity Framework 6, and I'm facing an issue with custom migrations.
I need to deal with two situations, one where there is a ...
1
vote
0
answers
346
views
SQL Server AlwaysEncrypted nvarchar incompatible [duplicate]
I want to use AlwaysEncrypted in a SQL 2016 Standard SP2 server with Entity Framework 6 but my query always fails with this error:
Microsoft.Data.SqlClient.SqlException (0x80131904): Operand type ...
0
votes
0
answers
55
views
Setting many-to-many navigation property to unmodified in EF6
I have an entity Order which has a many-to-many relationship with another entity Material. This relationship is represented by a collection navigation property Materials in the Order entity.
Since EF6 ...
0
votes
1
answer
212
views
Where is EF6.exe?
According to:
Source 1
Source 2
I should be able to find and extract ef6.exe by downloading Entity Framework from this site. After downloading, I am able to change entityframework.6.4.4.nupkg to ...
0
votes
0
answers
95
views
Windows Forms numericUpDown control does not update BindingSource
I have a numericUpDown control bound to a binding source. The bindingsource has a datasource that is a binding list of entities queried using Entity Framework.
_context.Tasks.Load();
_bindingSource....
0
votes
2
answers
4k
views
Getting Microsoft.Data.SqlClient trusted certificate error though not using that driver
I am using Visual Studio 2022 - v17.9.6.
When I try to modify or add either a typed dataset or an Entity Framework (v6) model from an existing SQL Server database, I get an error regarding a trusted ...
0
votes
0
answers
38
views
DbGeometry check for duplicates before insert in db takes too long
I have a problem inserting thousands of data into the database.
I need to check if a point with the exact same coordinates has already been inserted, but this operation takes too long, and over time ...
1
vote
1
answer
488
views
SQLite "attempt to write a readonly database error" when trying to READ from the database
I'm using Entity Framework 6 (not Core) and System.Data.SQLite.
I explicitly connect to the database with ReadOnly=True because I'm only opening it to read from it.
The database already exists and is ...
2
votes
1
answer
991
views
ProviderIncompatibleException with Npgsql, Postgresql 16.1 and .NET Framework 4.8
I have a legacy Entity Framework application running on .NET Framework 4.8.
Until recently, it connected well to Postgresql 11. Now we upgraded Postgresql to 16. We also upgraded the packages Npgsql, ...
0
votes
1
answer
166
views
How to change the data type of primary key using code first approach?
There was a legacy code base which used GUID as primary key and tables are already present in production and having 10-20 million records. Now, I wanted to change the primary key data type from GUID ...
0
votes
1
answer
84
views
How can I search for a DATE in Entity Framework
I'm trying to get a date from my database and I've tried different things, but nothing seems to work.
This is my date in the database 2024-04-18 19:47:36.337, it's defined as datetime in Microsoft SQL ...