Questions tagged [entity-framework-6]
Do NOT use this tag for Entity Framework Core 6 questions. This tag is for questions about Entity Framework 6, an ORM first released in 2013 and most recently updated to EF6.4 in 2019. It is not the same product as EF Core 6, first released in 2021
10,965
questions
0
votes
0
answers
26
views
Fix an error enable-migration C# using Visual Studio 2022
I'm trying to enable-migrations in Visual Studio 2022, but I get an error:
PM> add-migration InitialCreate
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework ...
0
votes
0
answers
26
views
Prevent Concurrently Selecting Same Row Value From SQL Server Table in EF
I have a table like this. Where row number will be incremented by 1 (Not using Identity). The incrementation is done by selecting a max value of particular category. for ex: if I want to add a product ...
2
votes
0
answers
50
views
VS2022 T4 EF6 Templates in .Net 6.0 projects are suddenly throwing serialization exceptions
I have a .Net 6.0 application (started out as .Net 5.0 in VS2019). I use the EF Core for data access. Our older applications are .Net 4.8, and we have a lot of T4 templates that we used to generate ...
1
vote
1
answer
26
views
The entity type required a primary key to be defined - but there is
I probably have a fairly trivial problem with EF configuring 1 table. This is how my class looks like:
public class Task
{
[Key]
public int Id { get; set; }
[Required]
public string ...
1
vote
1
answer
24
views
Cast exception when using IncludeFilter with EF6
So, I'm facing some problems when trying to run an IncludeFilter query. My project is built upon .NET 4.5.2 and I'm using EF6.
What I need is to be able to filter the results because using the ...
0
votes
1
answer
28
views
How to make migrations from another project on a console application using .net6?
I am trying to execute the command add-migration with a console application which I made a context in a project apart from the console application, but when I Try to run it, it gives me the error, I ...
0
votes
0
answers
17
views
Entity Framework 6 unable to update related models
I have list of models that are attached to a product model, insert is working, but when updated Entity is only updating the product model and ignoring the related models.
Sample code for update:
using ...
0
votes
0
answers
21
views
EF6 allow read but disable insert/update/delete during transaction
I am doing some "sync" between different platform. During this sync I try to add/update/remove records. For it I'm wrapping all functionality in TransactionScope
using (var tx = new ...
0
votes
1
answer
77
views
Linq .Distinct() add extraneous ordering
My entity has a computable geography::point column (represented by DbGeography type in code)
When I call a .Distinct() method on query for this entity it adds ORDER BY clause that's ordering by every ...
0
votes
0
answers
29
views
How to get specific columns from stored procedure return in .NET 6 and EF 6
Recently I updated my app to .net 6 and entity framework to 6.0.5 but some of my functionalities crashed which is expected. Namely, before this I was using entity framework 3.1.3. In my app I have ...
1
vote
0
answers
16
views
Include Operation Left out Join key
Here is my configuration and model class and information of Code First
public class TestDatabaseContext : DbContext
{
public TestDatabaseContext(string connectionString)
: base(new ...
0
votes
1
answer
34
views
Entity Framework 6 and reading encrypted fields using SqlQuery and ExecuteSqlCommand
We had to update our server, MS SQL 2019, and encrypt some fields.
Now, in both our application and in MS SQL Managament Studio, it works with a full read of a table (select * from whatever). However, ...
1
vote
2
answers
104
views
Entity Framework: Getting exception while inserting row in MySQL Table
I recently switched my database from SQL Server to MySQL. I am still using Entity Framework 6 to do CRUD operation in database. When I was using SQL Server as backend then I was setting "...
0
votes
0
answers
29
views
Is it possible to use EF 6, and Newtonsoft.Json at the same time?
I am using EF6 to manage multiple DataContexts (3 different and distinct data connections). In one DbContext, the view that I have been granted access to has a field that contains serialized Json ...
0
votes
0
answers
19
views
C# Entity Framework - How to insert, update and delete Association (many-many relationship) in database
I have generated model from database using Entity Framework. And have relation many to many between Invoice and PaymentMethod. In database I have table InvoicePaymentMethods that is not created in ...
0
votes
1
answer
46
views
.NET 6 EF 6.4. No connection string named 'xxx' could be found in the application config file
I'm creating a new C# WebApi project using .NET 6 and Entity Framework 6.4.4 (not EF Core) and MySql v8 using MySql Connector.net v8.
When I try to enable the migrations I get the following error
...
0
votes
0
answers
28
views
How to properly manage tracking over Entities in LinQ, EF6 and .net 6
i have a controller which should save a data from csv to database with some conditions: So half of columns goes to Employees, Children and Spouses tables and the other half of each record goes to ...
2
votes
2
answers
145
views
EF6:Parent context null inside same child query
My database contains below table in parent child relationships:-
Gender->Audit->Request(All are in 1:N Relationships)
I want to fetch all Genders with corresponding requests from database.
My ...
0
votes
1
answer
72
views
Trouble publishing ASP.NET project with Code First database to Azure - Permission
I cannot migrate my Code First database to Azure - Error hints at permission, but I can't figure out what's missing?
I have created an empty SQL-database in Azure
(I can publish the web site without ...
1
vote
0
answers
50
views
Query with large WHERE clause causes timeout exception in EF6
clients = (IQueryable<client>)opts.ApplyTo(_dbContext.sp_client.FromSqlRaw(
SqlQuerys.GetVisibleClients(),
new ...
0
votes
0
answers
37
views
How to include item fields in group select linq
I have a linq select. In the select I would like to have the components fields. How can I get the component fields? In my select I am grouping by componentId but I would like to include the component ...
3
votes
1
answer
56
views
How to filter IQueryable for null navigation property
Say I have 2 simple models (below), where 'User' contains a navigation property to 'UserDetail' (one-to-one relationship):
Database
CREATE TABLE [dbo].[UserDetail]
(
[UserId] [int] NOT NULL ...
0
votes
0
answers
21
views
Insert record in many-to-many when key is DatabaseGeneratedOption.None [duplicate]
I have two tables with many-to-many relation:
Employee
public class Employee
{
public int Id{ get; set; }
public string EmployeeFirstName { get; set; }
public string EmployeeLastName{ get; set; ...
0
votes
0
answers
17
views
Evalute part of LINQ expression before translating to SQL statements
Dim instanceOfMyClass As New MyClass()
'... Some code to manipulate instanceOfMyClass.MyArrayField
Dim thisYear = DateTime.Today.Year
Dim records = (
From i In dbContext.MyTable
Where i.MyCol >=...
0
votes
1
answer
8
views
CreateDbCommandDefinition in the custom DbProviderServices not called?
I need to intercept the call to the following method of DbProviderServices:
DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
So I need to ...
0
votes
1
answer
29
views
Why NHibernate is not sending extra select query in one-to-many during updating child?
I am quite new to NHibernate and I made simple app for testing NHibernate and Entity Framework performance. I noticed some problem with updating child in one-to-many relationship. During updating ...
-1
votes
0
answers
29
views
Soft delete with Entity Framework 6 consuming a service from a web api asp.net c#
I have a problem and I don't know how to implement a soft delete in my web api. I leave the capture of how I carry the delete method and the overwriting that I am doing of SaveChanges to intercept the ...
0
votes
1
answer
52
views
Why does a EF Core nullable entity cause "The expected type was 'System.String' but the actual value was null?"
Using Entity Framework 6 and .NET 6, I have a many-to-one relationship between Party and StatEntity:
modelBuilder.Entity<Party>()
.HasMany(p => p.PartyMembers)
.WithOne(p => p.Party);
...
0
votes
1
answer
157
views
SqlException while initializing database, but only on Azure and only with CF Migrations
I'm getting a SqlException when running initialization against an Azure SQL Server database: The server was not found or was not accessible.
Here's my Context code, in relevant part:
Private Sub New(...
0
votes
1
answer
122
views
Entity Framework : invalid object name "TableName1"
I have a problem with Entity Framework, I think I have a problem defining the one to many mapping, but I can't seem to find it.
When I try to save my changes and add my info to the database I get the ...
0
votes
1
answer
31
views
Create a relation from list of Ids - Entity Framework
Is there a way to create a relationship using a list of ids?
I have done this for a single property like below:
builder.HasOne<Employee>()
.WithMany()
.HasForeignKey(x => x....
0
votes
3
answers
40
views
Will DbContextTransaction.BeginTransaction prevent this race condition
I have a method that needs to "claim" a payment number to ensure it is available at a later time. I cannot just get a new payment number when ready to commit to the database, as the number ...
0
votes
0
answers
41
views
EF CORE "dotnet ef dbcontext scaffold" Define Data Types
I've been searching the web for a while, but can't find what I'm looking for.
Basically when I run the aforementioned code against my Sqlite DB, it generates all the classes etc, but instead of ...
0
votes
1
answer
180
views
ASP.NET Core 6 [FromQuery] return null values when binding to object
A picture is worth a thousand words - as you can see in the following screenshots, I'm not able to retrieve the parameters in the query string and bind them to the ApplyFilter model. I've tried [...
0
votes
1
answer
37
views
EntityFramework 6.4.4 - How to project collection to a custom object implementing IEnumerable<T>?
Cannot map to a custom object that implements IEnumerable ?
public class BranchCollection : IEnumerable<int>
{
public IEnumerable<int> BranchIds { get; set; } = new List<int>();...
0
votes
1
answer
17
views
Getting error trying to seed data using EF6 Code First
The models looks like this
public class Account : BaseEntity
{
public string AccountNumber { get; set; }
public string AccountTitle { get; set; }
public decimal CurrentBalance { get; ...
0
votes
1
answer
29
views
MissingMethodException when migrating from Ef 6.2 to 6.4.4
For a .net framework 4.8 project, when I update the EF reference from 6.2 to 6.4.4 the application throw an error
System.MissingMethodException: Unable find 'Void System.Data.Entity.Infrastructure....
0
votes
3
answers
53
views
Mocking EF in Xunit
I am new to unit testing and mocking but I am trying to add tests for existing CRUD functions. I know that I need to use MOQ library but I am not sure if I can do it with the function below. All CRUD ...
1
vote
1
answer
26
views
Connecting multiple tables using Entity Framework (code first)
I've created 2 table for my database, and connect them using foreign key,
example:
internal class Student
{
[Key]
public int StudentId { get; set; }
[Column(TypeName = "nvarchar(50)&...
-1
votes
1
answer
47
views
Entity Framework 6 Include retrieve data in null - relation one to one
Department and store model. They are a one to one relationship. when I do the (Include) only some models it brings me the complete data.
The data is correctly in the database
var orders = await ...
1
vote
0
answers
58
views
why is dependent entity with no principal entity not throwing a foreign key error on insert?
I'm using EF 6 and a mix of attributes and Fluent API to map a legacy database that I have to read/write to. I've done the relationship mapping in Fluent API.
I have also made each entity inherit from ...
0
votes
0
answers
27
views
Best way to handle a many to many relationship in EF6 ASP.NET MVC 5 and retrieve property from navigation property to list
A few years ago I took over a project from a previous developer and have been working my way through this system and adding to it as well as reconfiguring some aspects of it. The latest thing I've ...
0
votes
0
answers
16
views
Displaying message to end user with Concurrency enabled in Entity Framework 6
Ive been reading some articles to introduce Optimistic Concurrency into my MVC application using Entity Framework 6,
https://www.learnentityframeworkcore.com/concurrency
and
https://docs.microsoft.com/...
0
votes
1
answer
33
views
Is there a way to break DbContext to area in ASP.NET 6 framework?
I am creating a web application on the top of ASP.NET 6 framework. I am trying to figure out the best ORM to use for this project. I am leaning toward Entity Framework for the following reason
I'll ...
1
vote
1
answer
18
views
EF manually load / populate navigation property
I have the below code that fetches the data from service and attaches to the objects that was loaded from local database by EntityFramework 6!
We had the UserJob details before in our local database, ...
0
votes
0
answers
29
views
InvalidOperationException: Rewriting child expression from type 'EnumNameAddressType' to type 'System.Nullable`1[EnumNameAddressType]' is not allowed,
I have a bunch of derived types from this payload table in my app, and I have the code below in my DBContext that I am trying to do several things with. "HasDiscriminator" allows ...
1
vote
0
answers
26
views
In EF 6 DBInterception, how to get the actual value from DbModificationClause clause?
I'm researching with encrypting an EF 6 db column using db interceptors and custom annotation on the ef entity: https://www.codeguru.com/csharp/soft-deleting-entities-cleanly-using-entity-framework-6-...
0
votes
1
answer
28
views
Best way to update Database with List where items have been deleted
I'm working on a recipe Webapp with Asp.NET 6.0 and Razor pages. There are three database tables : recipe, ingredient and food.
Each Recipe has a Name, Preperation and list of Ingredients. I like to ...
0
votes
0
answers
17
views
Exclude AUTO_INCREMENT column value while using Entity framework Clone SetValues methods
I am using below code to clone records from one table to another using Entity Framework
List<MasterTableRecord> _records = context.MasterTableRecords
....
0
votes
1
answer
31
views
Entity framework 6 future is generating duplicate queries
Following code is written in entity framework 6 and entity framework plus library (futures)
using (var ctx = _contextCreator.PortalContext())
{
var q = "";
ctx.Database.Log = s => ...