Most voted "entity-framework" questions
ADO.NET Entity Framework is a set of tools for object-relational mapping or Object-Relational Mapping (ORM) for the . NET Framework by Microsoft, Since version 3.5 SP1.
Learn more…1,214 questions
Sort by count of
-
4
votes1
answer216
viewsTranscribe SELECT to LINQ query expression
How can I reproduce the query then to LINQ expression? SELECT nome_empresa, Count(funcionarios.id_funcionario) AS qtdfuncionario, Count(id_colaborador) AS qtdcolaboradores FROM empresas JOIN…
-
4
votes1
answer210
viewsTable relationship - EF
Good Afternoon! I have the "Service Order" and "Attachment" tables. In my "Service Order" table, I want to be able to attach the scanned service order and be able to attach pictures of the…
-
4
votes2
answers71
viewsGet null fields from the database with LINQ
I have a table of Gestor in the database where you store information of a user with Manager profile. In this table, I have two FK's: uniaoId and schoolboy. Well, that manager MUST belong to a union…
-
4
votes2
answers91
viewsChecking whether data persisted successfully
What would be the best way to get one bool indicating whether the method Add() and then SaveChanges() was successfully performed? Am I trying like this? Is that right? public bool…
-
4
votes2
answers88
viewsWhat is the Creation proxy for in the Entity framework?
What is the purpose of disabling this feature?
-
4
votes5
answers1602
viewsChange return /Date(1386295200000)/ to date format
I have a return from json that comes so from SqlServer: /Date(1386295200000)/ How to convert to date format dd/mm/yyyy?
-
4
votes1
answer1604
viewsSee Date only, in a Datetime field with LINQ
I’m generating a report in an app that I’m developing, but I have a little problem. When sending a query in a date interval, I can’t get anything, because it is a DATETIME (I can’t change to date…
-
4
votes1
answer114
viewsHow to optimize this code?
Is there any faster (performative) way to compare the current value with the previous (bank) value with Entity Framework? Instead of selecting Id for Id (according to property Discount code below),…
-
4
votes1
answer561
viewsMany Relationship Query for Many Entity Framework
I’m new to Entity Framework and Linq, so my doubt may be very simple, but it’s breaking my head. I have two entities: public class Fornecedor { public int FornecedorId { get; set; } public string…
-
4
votes1
answer117
viewsIs it bad practice to use "Guid" and "int" for the same bank?
In a project I’m developing I prioritize the use of Guid for PK because of the ease for me, but it has a table that would be more advantageous to use int. This is wrong?…
-
4
votes1
answer402
viewsUpdate One to Many Entity Framework
Hello, I need help with an update using Entity framework and relationship one for many. I believe it is something very basic, but I’m starting with EF and I can’t solve the problem. Artist and…
-
4
votes2
answers426
viewsClass relationship - (C# Entityframework)
Hello, I have a Person Class and an Address Class Ex. public class Pessoa { public int Id { get; set; } public string Nome { get; set; } ... public Endereco Endereco { get; set; } } public class…
-
4
votes1
answer1002
viewsUpdate Many to Many Entity Framework c#
I am having difficulty updating a record with entityframework, I will inform the whole structure below. In short, I have a register of artists, where these artists are related to categories.…
-
4
votes1
answer3602
viewsLinq Compare two lists of different types
I have two different lists A List<ProdutoTag> and B = List<Tag>: public class ProdutoTag { public Int64 ProdutoId { get; set; } public Int32 TagId { get; set; } public Double Peso { get;…
-
4
votes1
answer362
viewsOrder of execution of Migrations
Hello! In my first job, I worked using code-first with Entity Framework 4. At this time, I noticed a limitation in it: the generated Migrations only ran in order. For example, if in my branch two…
-
4
votes1
answer662
viewsNo Auto-Increment Primary Key for CPF in Entity Framework
The scenario is as follows: I have an Employee class. A primary key of it must be the employee CPF that the user type. The Problem: the key follows a default auto increment, not going according to…
-
4
votes3
answers113
viewsHow to implement custom features in a model on . NET?
I needed to implement some features in the model users but as you can see early on this class is automatically generated by Entity, so whenever I upgrade or recreate the model the custom…
-
4
votes3
answers342
viewsHow and where to implement business rules in the Entity Framework?
I have the following example of a software that uses Entity Framework, accessing a database with only one table called Produtos with the following fields: Field int produtoid. Field string…
-
4
votes2
answers123
viewsProblem creating user class (Identityuser) relationship using Identityframework
When I create any relationship with my user class: namespace Modelo.Cadastro { public class Usuario : IdentityUser { [StringLength(250, ErrorMessage = "O nome de usuário deve conter no mínimo 3…
c# asp.net-mvc entity-framework asp.net-identityasked 8 years, 4 months ago Luiz Henrique da Fonseca 41 -
4
votes2
answers621
viewsEntityframework . Asenumerable() or . Tolist()?
In one of the projects I picked up I saw the following code, which implements a data listing method of a given entity, but this listing is used only for reading: /// <summary> /// Listar todas…
-
4
votes2
answers184
viewsHow to use the IN clause in Lambda?
A doubt arose that I thought would be easy, but the content I found could not understand. Well, here’s the thing: I have the tables "Client" and "Errosproducao_client" where they relate form 1 to N,…
-
4
votes1
answer151
viewsUnique contexts of authenticated users
Using the @Gypsy recommended method in this answer (It is possible to leave connectionString dynamically?), I was able to get a dynamic connection, and using the idea of mapping a context with the…
-
4
votes2
answers638
viewsInsert checkbox dynamically by returning Json does not display Text?
I’m creating a list of Checkbox according to the selection of a Select on the same screen. No event change of select is called via ajax javascript, the method that returns a Json with list(value,…
-
4
votes1
answer424
viewsTwo classes mapping the same table with the Entity Framework
I’m trying to do the entity map two classes to the same table this is possible? Setting: Man identity this decoupled (Eduardo Pires' Master) from my domain and the presentation layer in the domain…
-
4
votes1
answer65
viewsEntity Framework - Object exclusion with relationship
I have a question to understand the behavior of Entity. Because when I pass null Entity should not "clean up" the relationship in the bank? My Model: public partial class Ocorrencia { [Key] public…
-
4
votes1
answer359
viewsUsing EF and Dapper in the same project
I’m making a simple insert of a user class, it is taking almost 10 seconds to record the information. So I tried to find other solutions to solve my performance problem and found the Dapper. My…
-
4
votes1
answer964
viewsHow to delete objects within a list?
I have the following code: using (Context contexto = new Context()) { List<Cliente> listCliente = contexto.Cliente.Where(x => x.Status == 0).ToList(); } How do I delete this result from the…
-
4
votes2
answers94
viewsHow to perform a Where using Entity Framework
I have a web application that I need to present a list containing some data, for that, I created the Model: Crm_Analise: public class Crm_Analise { [Key] public int id { get; set; } public string…
c# sql-server entity-framework asp.net-mvc-5asked 7 years, 4 months ago Thomas Erich Pimentel 3,059 -
4
votes2
answers178
viewsHow to update all records of all tables that have FK of a table
I have the following tables: CREATE TABLE Contrato ( [Id [int] NOT NULL IDENTITY, [Nome] [varchar](150), [Ativo] [bit] PRIMARY KEY ([Id]) ) CREATE TABLE [dbo].[ItemContrato] ( [Id] [int] NOT NULL…
-
4
votes1
answer212
viewsEntity Framework Query Many to Many
I’m starting to use the Entity Framework and I’m looking to make a query between two tables, Livroes and Autors, and their relationship is like Many to Many. I don’t know if it’s relevant but I’m…
-
4
votes1
answer578
viewsHow to generate a subquery in Line/EF
Hello, everybody. I have a situation, where I concatenate some subquerys Sqls that are concatenated into other Sqls queries, to return some values. I have several functions like these, because I use…
sql-server entity-framework linq linq-to-entities linq-to-sqlasked 5 years, 9 months ago Fabiano Richetti 41 -
4
votes2
answers176
viewsDoing a LINQ function that can be called in an EF query
I have the following expression: Where(cd => cd.Modal == modal) .Select(s => s.Volume) .DefaultIfEmpty(0) .Sum() what use to make a same calculation several times within a few querys through…
-
4
votes1
answer54
viewsExpression generation for EF with dynamic properties
I’d like to conduct a search on where for Entity Framework passing the name of the property you would like to compare as a string. For example, I have the following classes: public class ClientData…
-
3
votes1
answer1763
viewsSelf relationship at EF6
I need to make a relationship in one of the entities, as I do to reference the entity itself for both child records and parent record public class Comentario { public int IdComentario { get; set; }…
-
3
votes1
answer332
viewsHow to map an enumerator using Entitytypeconfiguration from Entity Framework 6?
Good evening, I have my next class public class Endereco { public string Bairro { get; set; } public string Cidade { get; set; } public EUF Estado { get; set; } } and my enumerator public enum EUF {…
entity-frameworkasked 10 years, 7 months ago Rod 9,412 -
3
votes3
answers3330
viewsGrab ID immediately after insertion
Entity and LINQ usage. I would like to know how I get a generated ID right after entering a record, before anyone else can enter it as well, that is, ensure that that ID is the one generated by me.…
-
3
votes1
answer70
viewsName of columns in web service return xml
That line gives me that mistake: if (db.T_TarefaParceiro.Max(p => p.IDTarefaParceiro) != null) The mistake The cast to value type 'System.Int32' failed because the materialized value is null.…
-
3
votes1
answer3372
viewsHow to make a complex SQL query in . NET MVC
I would like to know how to make a query, using multiple fields, multiple tables with Inner joins in ASP.NET MVC without having to put the SQL string in the code, using the Entity Framework. At the…
-
3
votes1
answer1261
viewsMap associative tables in the Entity
This has already happened. When I use an associative table in Entity, these tables usually don’t have PK. When this happens, I can’t map them. How can I map this type of table?
-
3
votes1
answer290
viewsQuestions regarding the use of . dbml files
I took a system in aspx(VS2008) and I will have to make some improvements, add other features and all this using MVC5. Well, there’s a web service, there’s a guy like that: static…
-
3
votes1
answer1208
viewsWork unit (Unit of Work) with repository
In ASP.NET MVC & Entity Framework, because many examples and some open-source projects find a unit of work together with the repository pattern whereas the DbContext is already a Unit of work,…
-
3
votes2
answers2094
viewsWhat is the difference between Attach, setar Entitystate for Modified and Currentvalues.Setvalues?
What’s the difference between methods to update a record through the Entityframework? Attach: dbContext.Pessoas.Attach(model); Setar the State from an entrance to EntityState.Modified:…
entity-frameworkasked 10 years ago user8052 -
3
votes1
answer82
viewsDoubt about performance in using the statement
Which of the two ways to verify if a record of such TYPE has ever been registered is more performative? Are there differences, errors? What are the implications? The block using frees only…
-
3
votes1
answer695
viewsError when calculating date difference in Entity with Linq to Entities
Before I was like this my expression: var resultado = db.T_CRM_StatusPDV .Join(db.T_PDV, t1 => t1.DE_Cnpj, t2 => t2.CNPJ, (t1, t2) => new { t1, t2}) .Where(dt =>…
-
3
votes2
answers201
viewsHow do I return an existing item in my enumerable via Contains?
I have an enumerable, and I intend to query through a code per parameter. if the enumerable "Contains" Code, then it will return to me all items that are with this Code. See I was trying to do it…
-
3
votes3
answers606
viewsCorrect Inheritance in Entity Framework
I have a mother class DadosClientes and two child classes DadosClientesPF, and DadosClientesPJ. Instance DadosCliente has the field: Nome, Telefone Instance DadosClientePF has the field: CPF…
-
3
votes1
answer1021
viewsSelect [with aggregated functions] group by in Lambda
How do I convert the following select SELECT TOP (60) COUNT(*) AS QTD, SUM(Duration) AS Total, AVG(Duration) AS Media, MIN(Duration) AS Menor, LEFT(TextData, 80) AS TextData FROM Traces WITH…
-
3
votes1
answer1373
viewsProblem returning Entity models: "The Entity or Complex type ... cannot be constructed in a LINQ to Entities query"
I’m trying to return a list of objects generated by the Entity Framework Database First but I get this error: The Entity or Complex type 'leaosites04Model.TB_LEMBRETES' cannot be constructed in a…
c# entity-framework linq entity-framework-6 linq-to-entitiesasked 10 years, 4 months ago Reynaldo 141 -
3
votes1
answer282
viewsRelationship between different contextual classes Entity Framework
I have a problem saving an object, due to it having relationship in a different context, I wonder if there is a way to solve this problem.
-
3
votes3
answers1833
viewsDelete Relate Record using Entity Framework
Good morning. I am working with Entity Framework and I have a problem updating a relational table. For example, I have a product with several categories, in the edition I remove the category x of…