Questions tagged [entity-framework]

42525 questions
1

votes
0

answer
6

Views

change entity framework core code first migration name format

ef core using system calendar format for generating migration names. example of standard migration name for the Gregorian calendar on windows: 20190206144020_MIGRATION-NAME But if the date format of Windows is something other than the Gregorian, like Persian calendar the ef core migration name gene...
AliReza
1

votes
0

answer
12

Views

Verifying database schema in a database-first application?

I'm currently working on a project that quite often fails due to enormous amounts of models and the wrong approach that was taken (database-first) in such app. While I can't remake the entire application using code-first approach, is there any way to verify database to find all missing relations, co...
JCode
0

votes
0

answer
12

Views

Force inner join from EF Cores Include() on optional relationship

We changed a relationship from required to optional, now the resulting SQL produced by EF Core's Include() does a left outer join rather than inner join. Problem is that those optional entities have query filters on them that is required. Let's say we have the following; public class First { public...
HenrikM
0

votes
0

answer
6

Views

Linq, EF Core - group by on one field and use other field to get list of data from other table

Can someone help me. I tried everything, nothing worked. I have data in this format table1 Id T_Id 4 2 6 5 6 7 table2 T_Id fname lname 2 mary smith 5 john pope 7 steve blair I want to get data in following format using linq query with EF Core. [{ 'Id' : '4', 'users':[{ 'T_I...
Shamal
1

votes
1

answer
65

Views

ASP.NET Core DI with Simple Injector sharing DbContext

I'm setting up an ASP.NET Core project and following a CQRS pattern basing my work on the Tripod project. I've followed the Simple Injector integration guide but a little puzzled on one point... I want to keep make use of the UseInMemoryDatabase option for testing and can only find examples of that...
Stephen York
1

votes
2

answer
77

Views

Entity Framework Core SQLite Connection String Keyword not supported: version

I created a ASP.NET MVC website using .NET Core 2.2 using a SQLite database. So far it's working well. Trouble begins when I want to add SQLite-specific keywords to the connection string, such as Data Source=~\\App_Data\\MyDb.db; Version=3; DateTimeFormat=UnixEpoch; DateTimeKind=Utc Now I get Keywor...
Etienne Charland
1

votes
1

answer
83

Views

EF Core with Mysql not scaffolding BIT(1) to Boolean

I am trying to generate DB classes from the existing database (DB first) through. Net core CLI. The DB was perfectly working with EF5 and .net4.5 but after migrate to EF core the bit(1) field is not scaffolding as bool instead it is generating as short. Also tried with TinyInt(1) but no luck. Techno...
ni3.net
1

votes
2

answer
128

Views

Get nested data and sharp into DTO with nested DTO

I'm newbie to EF, Linq and C# in general, I'm stuck with developing following. I cannot map data into structure like this: Id, Actions [ Action1, Action2, Action3 ] I have 2 DTO classes like this: public class TestDTO { public int TestId { get; set; } public TestDTO2[] Actions { get; set; } } and p...
1

votes
1

answer
133

Views

Microsoft.Extensions.EntityFrameworkCore namespace not found in .NET Core 2.2

I'm reading the book 'Pro ASP.NET Core MVC 2' and following his samples, and have reached the point where he introduces EF Core. He says to add the following to the .csproj file... ...and then add the following to the ConfigureServices method in Startup.cs... services.AddDbContext(options => options...
Avrohom Yisroel
1

votes
1

answer
19

Views

Trying to create a tree of nodes with LINQ to SQL produces NotSupportedException

I have the following code that works perfectly inside LINQPad as you can see in the screenshot. Please, notice the Results part in the bottom part of the screen, where the tree of nodes is shown: But when I run it in my application, it shows the following exception: System.NotSupportedException Unab...
SuperJMN
1

votes
1

answer
32

Views

Move DbSet<TEntity> properties to a Separate Class in Entity Framework Core

Here is what I have currently in MyContext class public class MyContext:DbContext { public DbSet Countries { get; set; } public DbSet States { get; set; } } What I want is to place all these DbSet properties into a separate file and just have one statement on MyContext class to add all...
Bipn Paul
1

votes
2

answer
41

Views

How to use Entity Framework in-memory database in an F#?

I am trying to use Entity Framework Core with F# with the in memory database for a very simple use case: open System open Microsoft.EntityFrameworkCore type Position = { X: double Y: double } type Airport = { Id: Guid Name: string Position: Position } type MyContext = inherit DbContext new() = { inh...
Ehouarn Perret
1

votes
1

answer
52

Views

How do I do an async query without enumerating the data?

I'm trying to work out how to write a generic async GetAll database method in Entity Framework Core without enumerating the data. I want GetAll to be async, but don't want it to enumerate the data, so that I can add a Where method afterwards, and have that applied to the database query.. List custom...
Avrohom Yisroel
1

votes
3

answer
39

Views

edit only changed or mentionned values with entity framework core

I need to update only mentioned fields in the put request body , the current issue is that all the values that are not mentioned in the entity to update are set to null below is my currrent update implementation in the generic repository. public virtual void Update(T entity) { Context.Attach(entity...
Jawhar Jarrar
1

votes
2

answer
40

Views

Having two classes representing the same table in Entity Framework?

I am trying to clean up some Entity Framework data contexts that were originally created without any naming conventions. I would like to keep the old classes but also have the new, properly named class available at the same time so that all the other projects that use these data contexts don't need...
John S
1

votes
2

answer
57

Views

Is there a way to automatically create CRUD for EF Model (DB First currently)

I am creating a WPF app and I have an existing DB that I would like to use and NOT recreate. I will if I have to, but I would rather not. The DB Is sqlite and when I add it to my data later and create a DataModel based on the DB, I get the model and the DB Context, however there are no methods creat...
Charlie
0

votes
1

answer
13

Views

LINQ with Include and Where not showing desired results

I have a linq statement that combines Residents and Requests table like so var resident = await _context.Resident .Include(s => s.Requests) .FirstOrDefaultAsync(m => m.ID == id); The problem is that all requests show up even those that are not related to the Resident. I have tried ad...
Podge Dimagiba
0

votes
0

answer
13

Views

C# Conditionally disposing of Entity Framework DbContext only when needed

I'm trying to make my code be intelligent enough to only open and dispose of an Entity Framework DBcontext if it's only needed within the Current execution lifetime of the method in question. Basically, if a real context is being passed into the method then I do Not want to dispose of it. However, i...
crazyTech
0

votes
0

answer
22

Views

Unable to pass null parameter in winform's event handler?

i want to subsequently apply filters to my search Say ' if I give 10K as the myFee value it should show all subjects with 10K Fees however if after this I give year 2014 it should show results applying both fee and year constraint simultaneously currently, I am getting a correct result if I give va...
Chameleon
0

votes
0

answer
14

Views

Get Enity Instance by name

I receive an entity name as string incoming. ObjectContext objContext = ((IObjectContextAdapter)db).ObjectContext; MetadataWorkspace workspace = objContext.MetadataWorkspace; IEnumerable entitytypes = workspace.GetItems(DataSpace.SSpace); IList lst = new List(); EntityType entityType = entitytypes.W...
edelwater
0

votes
0

answer
11

Views

How to bind relational data from SQL-Server to an Entity with one-to-many relationship

I am using entity-framework6 with .net core. I was having some complex calculations to get some results from database so i created a stored procedure in database which gives me the list of properties as out put. I have successfully binded data to Property Object from database result. as shown below...
zulqarnain jalil
0

votes
0

answer
12

Views

What is the equivalent of entity framework in Flask?

When I worked with c# on asp net core, I made que models first and then created the database. When creating the models, I had for example, a list. So the models where linked. Example, a user had a list of posts. Using asp net core it was just pressing a few buttons and the program would create a dat...
Max
3

votes
2

answer
117

Views

Unable to determine the provider name for provider factory of type 'System.Data.SqlClient.SqlClientFactory

I have a .Net Core WebApi project with a controller that makes calls to a service, class library, to get data. The service uses Entity Framework, not EFCore. The error fails, here: public IEnumerable GetAll() { return _dbContext.Set().AsNoTracking().ToList(); } Here is the error: System.NotSupport...
Jim Kiely
1

votes
1

answer
1.1k

Views

What's the correct way to use Effort with Entity Framework 6?

I'm trying to get some test code working using the Effort data provider with Entity Framework 6. What I'm trying to do seems like it should be the absolute simplest use-case, but I'm just not able to get things to work. Here is my DbContext class: public class CcdReductionFrameCatalogue : DbContex...
Tim Long
1

votes
1

answer
383

Views

MVC 5 Unit tests vs integration tests

I'm currently working a MVC 5 project using Entity Framework 5 (I may switch to 6 soon). I use database first and MySQL with an existing database (with about 40 tables). This project started as a “proof of concept” and now my company decided to go with the software I'm developing. I am strugglin...
Pierre
1

votes
1

answer
1.4k

Views

context.Database.ExecuteSqlCommand - Error code 701 - Microsoft Azure

I have the following code in the migration configuration seeding method: string sqlQuery = // 22 mb file contents context.Database.ExecuteSqlCommand( sqlQuery ); The ExecuteSqlCommand function is making Azure throw this error: The service has encountered an error processing your request. Please try...
Jimmyt1988
0

votes
1

answer
890

Views

Can I create a constant expression for use in attribute parameter?

As anyone answering this already knows, parameters of attributes require constant expressions. Optional parameters (for anything, not just attributes) also require constant expressions for their default values. The (albeit minor) inconvenience I'm having is with RegularExpressionAttribute's pattern...
Lopsided
0

votes
2

answer
16

Views

Creating a XML file from a database with a model C#

So I need to create a method that makes an XML file from a database, I have already written the stored procedures that get the information from a database for the XML now I only need to write the part where I convert my database to a XML file using the properties of another class that I have written...
Uros Dimitrijevic
0

votes
2

answer
11

Views

Model's indexes doesn't validate

Table in postgres: CREATE TABLE 'public'.'filters' ( 'Id' int4 NOT NULL DEFAULT nextval(''filters_Id_seq''::regclass), 'Name' varchar(200) COLLATE 'pg_catalog'.'default' NOT NULL DEFAULT ''::character varying, 'Type' int4 NOT NULL, 'Alias' varchar(200) COLLATE 'pg_catalog'.'default' NOT NULL DEFAULT...
TrueGameover
0

votes
0

answer
3

Views

Entity Framework Core's AddRangeAsync() doesn't work in a generic method

This works: await AddRangeAsync(myEntities); But this doesn't work: await AddEntities(myEntities); ...when I try to use this function: private async Task AddEntities(IEnumerable entities) { await AddRangeAsync(entities); } I get an error: 'The entity type 'List' was not found. Ensure that the entity...
Chris
0

votes
0

answer
25

Views

How to keep DbContext in Connected state with Web API

Since Web APIs are stateless when you have EF Core backend after any request the DbContext would be disconnected. Therefore we have made QueryTracking as NoTracking since default behavior TrackAll doesn't give any benefit since its a web application DbContext.ChangeTracker.QueryTrackingBehavior = Q...
Nipuna
1

votes
1

answer
3.7k

Views

How to fix 'No property or field exists in type' error?

I got this error when trying to sort any columns that are not in the Order table, if I use OrderBy('Customer.CompanyName' + ' ' + sortDir) the error will gone but all the columns will become unable to sort. The OrderBy method used below come from here. What is the cause of the problem ? public Acti...
Phantom
1

votes
2

answer
1.6k

Views

Do I use Snapshot file, migration file or data annotations in my EF Core to update database?

I'm trying to understand the different types of migration paths we can choose when developing an ASP.NET Core 1.0 application with EF Core. When I created my first Core application I noticed it generated a ApplicationDbContextModelSnapshot class that uses a ModelBuilder to build the model. Then I r...
Ray
1

votes
1

answer
805

Views

Unknown CS1003 Error

I can't compile my project for code-first migrations in entity framework past a certain point. I am reading in values from xml to populate a table. I have the following code: //EnrolmentProgramStartDate var programQuery = from r in context.EnrolmentPrograms select r; var programList = programQuery.T...
Ben
0

votes
0

answer
12

Views

Convert Dictionary to ICollection in Entity Framework Core

Here I am stucked with the conversion of dictionary to Icollection in EF Core. I have Dictionary in FlatEmployee class in which I am storing list of key, value pair in database. I have declared like this: public class FlatEmployee { public int EmployeeId { get; set; } public Dictionary PayAndAllowan...
Iswar
1

votes
1

answer
1.6k

Views

System.OutOfMemoryException Entity Framework 6 for db.SaveChanges

I'm running a batch job of inserting events into a database with entity framework. Total size varies but around 3.5 million events are normal. This list is split up into groups of 60-500k events that are then added to the database. However when around one million events have been added I get System....
Ogglas
1

votes
3

answer
456

Views

Get results matching a list of Ids using Linq

I am trying to get the list of gameIds that satisfy all the genreIds included in a a List. The tables (partial): editorial_list: game_id content game_genres (game can belong to several genres): id game_id genre_id I need to get the list of the game Ids of games that exists for all the genre_id's in...
Idan Shechter
1

votes
2

answer
1.5k

Views

How to perform a join in c# .net core Entity Framework using

I have this relation ship. In both of this model I have a navigation properties, however I still don't know how to use them. The Customer Model public class Customer { public int Id { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } [Requi...
user3862830
1

votes
2

answer
4.1k

Views

ef core migration insert data

I'd like to insert data into table in migration. Is it possible? Migration needs parameterless constructor available and I'd like to use db context defined in Startup.cs file (best I'd like to get it throught dependency injection). How do that?
Marek
1

votes
1

answer
84

Views

How to properly use IPluralizer in IDesignTimeServices

In my app I use code-first approach and I'm adding entities to DbContext only via IEntityTypeConfiguration. My goal is to achieve pluralized table names i.e. Models for Model. After reading documentation, article, This question my understading would be that my pluralizer should be registered and as...
WueF

View additional questions