Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [entity-framework-6]

For questions about the The ADO.NET Entity Framework Version 6. Add the generic [entity-framework] tag as well if your question is not limited to the EF6 version.

-2
votes
2answers
43 views

WHERE IN clause AS object Entity Framework

If I have a Company objects : var companies = db.Companies.Where(...); And a User objects which related to Company object one-to-many : var users = db.Users.Where(...); How I can achieve a ...
0
votes
1answer
33 views

How to handle limitation of in-memory entities to Unit Test class/service which is using EF 6

I going to unit test a service which is using Entity Framework 6. Sample scenario, it would have Blog and Post entity, Blog having zero or more Posts. In the service method it would return list of ...
0
votes
0answers
13 views

Automapper ProjectTo does not allow mapping properties to custom methods

I'm using EntityFramework 6.2.0 and Automapper 6.2.2. I need to map the entity Cart to CartDto. CartDto has a property Total which needs to be mapped to the result of Cart.GetTotal(). I'd like to use ....
0
votes
1answer
21 views

Can I use a separate query plan cache per session?

I have a multi-tenant ASP.NET application, and our database is set up with soft deletes. Initially, we handled the restriction of data directly at the query level, e.g: var foos = context.Foos.Where(...
0
votes
2answers
54 views

Entity Framework 6 related entity where datetime clause doesn't translate to SQL

How do I get the date filter into the generated SQL query without access to database context? EF makes some very expensive queries. I don't cast or use the results as IEnumerable, so I would expect ...
0
votes
3answers
23 views

Select max as second criteria with Linq

i'm trying to get all rows who has some field = max of that field to be able to explain my doubt, I will leave an example of model class model { [Key] [Column(Order=0)] public int Key { ...
0
votes
3answers
30 views

How do I execute RAW SQL query and dump it to JSON in ASP.NET MVC 5 (EF 6)?

I want to execute a raw SQL query as shown below: select material, method, count(*) from treatment group by material, method and return it as JSON object. Because EF 6 Framework allows the ...
0
votes
2answers
26 views

Why is EF inserting new data for entities that I'm not specifying?

I'm going to chunk this down to as simple a case as I can, but this happens for everything. I'm basing most of my data model POCO objects on a BaseDataObject defined as follows: public class ...
1
vote
1answer
54 views

Understanding Entity Framework transactions and their behavior

I am using Entity Framework code-first and it's behaving very strangely when I use transactions. In the code below you will find a simple example. As you can see - even though transactions are ...
0
votes
2answers
58 views

Is there a simple way using data annotations or a custom type to use a value stored as a string in SQL as a DateTime in EF?

I have a database where all of the dates and times are stored as strings [yyyyMMdd] and [hhmmss] respectively. Is there a data annotation I can add in the POCO class so that it is recognised as the ...
0
votes
1answer
48 views

Divide List object in two objects with Entity Framework

I have a question... I need divide a List in two objects, i have the next code: public class User { [Key] public Guid Id { get; set; } public virtual List<PersonalData> ...
0
votes
1answer
32 views

C# How to update an entity with an Enum as property with EF6?

I'm trying to update an Order entity: public class Order { public int Id { get; set; } public PaymentMethod PaymentMethod { get; set; } } PaymetMethod.cs: public enum PaymentMethod { [...
1
vote
1answer
686 views

Entity Framework flexible cache

I am looking for a cache system that works with Entity Framework 6+. Either to find a suitable library or implement it myself. I have already investigated these two open source cache providers: ...
1
vote
1answer
1k views

EntityFramework.Plus: One or more validation errors were detected during model generation

I am using the audit feature of EntityFramework.Plus in an EF6 Code First project. When I add the following code: public virtual DbSet<AuditEntry> AuditEntries { get; set; } public virtual ...
21
votes
7answers
19k views

Bulk deleting rows with RemoveRange()

I am trying to delete multiple rows from a table. In regular SQL Server, this would be simple as this: DELETE FROM Table WHERE Table.Column = 'SomeRandomValue' AND Table.Column2 = '...
1
vote
1answer
1k views

Modify the expression tree of IQueryable.Include() to add condition to the join

Basically, I would like to implement a repository that filters all the soft deleted records even through navigation properties. So I have a base entity, something like that: public abstract class ...
6
votes
1answer
3k views

Is there a non-commercial alternative to Z.EntityFramework.Extensions?

Entity Framework can be very slow on mass insert/update/delete operations. Even the often suggested tweaks to turn off AutoDetectChanges and/or ValidateOnSaveEnabled does not always help. I have come ...
3
votes
1answer
3k views

Entity Framework 6 DbSet AddRange vs IDbSet Add - How Can AddRange be so much faster?

I was playing around with Entity Framework 6 on my home computer and decided to try out inserting a fairly large amount of rows, around 430k. My first try looked like this, yes I know it can be ...
4
votes
2answers
5k views

How to filter “Include” entities in entity framework?

Entities: public class Room { public Room() { this.Reservations = new HashSet<Reservation>(); } public int Id { get; set; } public ...
6
votes
1answer
6k views

Entity Framework include filter child collection

I have some difficulty to add some filter condition for included items in my LINQ query. My query is like var item = _Context.Order.Include("Inner") .Include("Inner.first") ....
7
votes
2answers
2k views

What logic determines the insert order of Entity Framework 6

So, I have a DBContext, and I am doing the following operations: dbContext.SomeTables1.Add(object1) dbContext.SomeTables2.AddRange(objectArray2) dbContext.SomeTables3.AddRange(objectArray3) dbContext....
32
votes
4answers
18k views

How can I use use Entity Framework to do a MERGE when I don't know if the record exists?

In this SO answer about Entity Framework and MERGE, the example for how to code it is this: public void SaveOrUpdate(MyEntity entity) { if (entity.Id == 0) { context.MyEntities.AddObject(...
1
vote
1answer
33 views

Entity Framework inserts only one record

I'm saving a record in my database by passing 3 parameters, the number parameter is passed to pick the number of records from one table to another table. However the loop written inserts only 1 record ...
-1
votes
2answers
39 views

Bind additonal elements In ICollection<Model> Without breaking EF EDMX

I have trouble binding data into a DataGrid with MVVM approach. Might be silly but I'm stuck. I have an EF6 table EFTable which looks something like this namespace Database.Models { [Table(...
0
votes
2answers
68 views

WPF application runs in debug, crashes when deployed after a button click

I've created a WPF application in VS17. I used Entity Framework code first Version 6.0 for data. I also used some third-party libraries such as Newtonsoft.Json and EPPlus. I installed all of these ...
0
votes
0answers
44 views

Entity Framework 6 DateTime.ToString().Contains() Error [duplicate]

Hoping someone can help me out. I have the EF query below which throws an exception, can anyone recommend a different approach. I have seen lots of examples where the solution is to call .ToList() ...
1
vote
0answers
27 views

Entity Framework 6 Code First - Map Function Or StoredProc to primative type

I am looking to implement something like the following" string searchValue = "Jun"; var users = context.Users .Where(x => x.BirthDate.SomeWhackySqlFunction(searchTerm)) ....
0
votes
0answers
26 views

Is it possible to run a raw SQL query in Entity Framework using Fluent Entity Configuration?

I'm using Entity Framework Code-First v 6.3.1 and trying to run a Raw SQL query according to this post: var result = context.ProcessStatuses.SqlQuery("SELECT * FROM ProcessStatus where Date_Modified=@...
3
votes
1answer
116 views
+50

How to retrieve Entity Configuration from Fluent Api

Using Entity-Framework 6 I'm able to set up the configuration through Fluent Api like this: public class ApplicationUserConfiguration : EntityTypeConfiguration<ApplicationUser> { public ...
0
votes
0answers
13 views

No owin.Environment item was found in the context.After moving my Startup.Auth.cs from project to DAL class library

after moving both of them also projects runs properly but when try to login or register its giving following exception i attached the image here Message: No owin.Environment item was found in the ...
0
votes
0answers
9 views

Bulk Add EF6 with properties that may or moy not exit

I am trying to bulk seed with entity framework 6 code-first, however when i use DBContext.Products.AddRange((List<Product>)static_class.GetProductsList()); I'm confronted with a duplicate key ...
3
votes
0answers
413 views

Entity Framework 6.1.1 and Large Model Issue

I've a huge database with around +1100 tables in it, I am trying to use entity framework and split the tables to multiple different diagrams to avoid the model crashes issue, I've added around 300+ ...
0
votes
1answer
31 views

Getting TEntity type in logging

I'm using Entity Framework 6 in C# and have implemented my own class of DatabaseLogFormatter to be able to format what comes out of the log. I would like to add some more detail to the log the ...
0
votes
1answer
19 views

Fetch data from other table using fergin key using Entity Framework

I have stuck with a problem where I can't get access to releted objects. Table Customers CustomerId | CurrencyId | AreaId 4 | 1 | 4 Table CustomersToArea CustomerAreaId | AreaId ...
1
vote
0answers
11 views

How to get an EntityFramework Migration to run different SQL for different database providers

I've an Entity Framework 6 application. I'm migrating it from SQL Server to PostgreSQL. One of the migrations looks like this: using System.Data.Entity.Migrations; public partial class ...
1
vote
1answer
81 views

RPC error on update EDMX file

When I want update my entity framework model(.edmx) i have following error Unable to generate the model because of the following exception: 'System.Data.Entity.Core.EntityCommandExecutionException: ...
22
votes
4answers
26k views

Entity Framework 6 Code First function mapping

I want integrate Entity Framework 6 to our system, but have problem. I want to use Code First. I don’t want to use Database First *.edmx file for other reasons. I use attribute mapping [Table], [...
0
votes
0answers
14 views

db.Configuration.ProxyCreationEnabled not working [Circular Rererences]

I have a simple method that make some simple operations on tables: [HttpPost] public ActionResult SaveCoachingPlan(factCoachingPlan cp) { db.Configuration.ProxyCreationEnabled = ...
0
votes
0answers
8 views

EntitiFramework 6 is not chaching linq query results [duplicate]

As a test, I setup a controller action which executes 1 query 2 times in the same DbContext to see if the query was chached. private TestWebAppContext db = new TestWebAppContext(); public void Log(...
0
votes
2answers
59 views

Database first with EF6 SqlAnywhere provider in VS2017

Having already followed the advice in the SAP website documentation and installed the developer edition of SQLAnywhere 17, and also having manually run the installer for VS integration that is ...
0
votes
2answers
56 views

EF6: saving to same entity using dbContext in async tasks

I load an object/entity from the database: var db = new DbContext(); //... var item = db.Items.First(); Then I want to perform two asynchronous tasks, that when returned, update data on the item: ...
0
votes
2answers
52 views

Changing the output DTO (return value) of the GetAll method in an AsyncCrudAppService

I'm using ABP's AsyncCrudAppService in my AppServices. Here's my interface: public interface IAssetRequisitionAppService : IAsyncCrudAppService <AssetRequisitionDto, Guid, GetAllInput, ...
1
vote
2answers
51 views

C# addin with EF6 - No connection string named 'Entities' could be found in the application config file

I'm working right now on upgrading a VB.net Solidworks addin to a better version of it but in CSharp. I'm trying to migrate towards Entity Framework 6 when it comes to Database integration. So I ...
0
votes
2answers
34 views

Searching for multiple strings using single database query with entity framework and LINQ

Assuming I have a database table (aTable) with two columns id : int name: string Requirements: I want to retrieve entries where aTable.name is like a list of strings (stringsToSearchFor). What ...
0
votes
1answer
51 views

Unable To populate view or view model Updaed

Hi I am following up on this question here and working through a proof of concept for a SPA using our Company database data from a series of examples / articles Using Web API 2 with Entity Framework ...
1
vote
0answers
25 views

While migrating EF6 from SQL Server to Oracle. “Oracle Data Provider for .NET does not support Time” getting this issue

I have a requirement to migrate the Asp.Net with EF6 from SQL Server to an Oracle database. When running enable-migration, I get this error: Oracle Data Provider for .NET does not support Time ...
1
vote
1answer
41 views

Entity Framework - get related items without explicit reference using Fluent API configurations

Let's say I have database table A with optional property X. I have table B with a composite key (Y, X). These two tables are not explicitly related in any way. e.g. create table A ( Id ...
0
votes
3answers
302 views

More efficient way to perform a UPSERT with EF6

I have the following code block that basically checks for the existance of a entity in the DB and loads it to context for updating or in case it does not exist adds the new entity. using (var db = ...
0
votes
1answer
24 views

The mapping of CLR type to EDM type is ambiguous because multiple CLR types

I have two Databases but both databases have same schema.I have added their edmx files in different folders to separate namespaces but still I am getting this exception: The mapping of CLR type to ...
2
votes
2answers
12k views

Entity Framework The context cannot be used while the model is being created

My unit of work class is mentioned below and I am using Ninject and I have tried injecting IUnitOfWork per request per thread scope, transient etc. but I am still getting error which is: "Message":"...