Most voted "code-first" questions
Methodology for mapping between classes . NET and database structures.
Learn more…80 questions
Sort by count of
-
12
votes1
answer680
viewsCode First versus Database First?
I’m used to creating projects on Asp.net-MVC with Entity Framework Database First. From a modeling, the database and the system are created. However, I see a lot of programmers prefer Code First,…
asp.net-mvc entity-framework code-first database-firstasked 10 years, 1 month ago Andre Figueiredo 5,030 -
10
votes2
answers5236
viewsRelationship N for N and One for N with Codefirst Data Annotations
How can I Relationship N to N and One to N using Data Annotations? For example: A sales drive has a user, and a user can have multiple drives. This same sales movement has several products, and each…
-
8
votes3
answers1381
viewsWhat is the difference between Data Annotations and Fluent API?
What is the difference between Data Annotations and Fluent API? Is there a restriction between one or the other? Improve performance or are just two ways to do the same thing?
-
8
votes2
answers708
viewsCode First and Calculated Fields
I have a class Pedido, which has a calculated field, which is the order value, composed of the sum of the items minus the discount. public class Pedido { public ICollection<PedidoItem> Itens {…
-
7
votes2
answers4310
viewsHow to prevent a property from being mapped to an entity in the Entity Framework?
I need to enter a property in the model class, but when I enter the code first, it says the table already exists and changes have been made. My code: public class Data { [Key] public int Id { get;…
c# entity-framework asp.net-mvc-4 property code-firstasked 10 years, 9 months ago Luciano Azevedo 402 -
7
votes1
answer3147
viewsHelp with setting up Dbcontext with Entityframework using good practices
I have my application divided into layers with Class Library and my layer with the Entity Framework, where I set up the DbContext, is the Repository. My inherited Dbcontext class: public class…
-
7
votes1
answer404
viewsCode First Mapping with Data Annotations
I am creating a project using mapping through DataAnnotations with Code First (similar to the Hibernate), without the use of FluentAPI. It turns out that in implementing this process, some…
-
6
votes1
answer523
viewsI’m not getting a Oracle file with Code First
Here’s what I’m doing: Folder Model dou Add > New Item follows pictures Then select ADO.Net Entity, give a name and ADD I select Code First and give Next Well in this step, I select , and look at…
-
6
votes1
answer325
viewsRun Insert in Migrations Entity Framework
I am developing an ASP.NET MVC project with Entity Framework Code First. I already checked the bank and managed the first Migrations, my question is: has how to execute a insert right after creating…
-
6
votes1
answer813
viewsSelf Relationship in EF
I’m having the following problem creating two self relationships. When rotating the Update-Database The following error message appears: Unable to determine the main end of an Association between…
c# entity-framework asp.net-mvc-5 entity-framework-6 code-firstasked 8 years, 4 months ago Lucas Ost 319 -
5
votes2
answers221
viewsWhat is the reason for using Dbmigration in Codefirst?
What is the goal of using Dbmigration when developing a project using Codefirst? Using it is a good practice, or is something that does not cause major impacts on the implementation and/or…
-
5
votes1
answer684
viewsIs it possible to use composite key for Entity Framework with Model First?
I have the modeling down and will need to map composite keys like the Embedded id of Hibernate, but in the Entity framework using the model first, it is possible ?…
-
4
votes2
answers442
viewsCode First with Complex Types, when making Scaffolding the properties of Complex Types are not found in the views
I’m following Sergey Barskiy’s presentation on http://www.youtube.com/watch?v=l3WzYZsN0gU, where it demonstrates the Entity Framework approach with Code First. I loved it, but I had a problem. In…
c# asp.net-mvc entity-framework code-firstasked 10 years, 10 months ago Guilherme de Jesus Santos 6,566 -
4
votes2
answers2690
viewsEF 6, Fluent Api mapping in inheritance classes
I am training in class mapping for the Entity Framework using the Fluent API and I have some questions. The first is as follows: Map a Foreign key with attributes would be like this: public int…
-
4
votes1
answer954
viewsHow to create a foreign key in a table where data already exists, in Entityframework with Code-First?
I have a system already in production of which the client requested a modification. The modification is the creation of an EMPLOYEES table that will relate to the MOVEMENT table, creating a 1:N…
-
4
votes1
answer288
viewsCreate unique attribute beyond Primary Key in code-first
I’m creating a table of Logradouro where the countryside CEP is not the primary key, but should be unique. How do I do it using code-first in the Entity 6.0? To create primary key I use the method…
-
4
votes1
answer100
viewsAspnet MVC database first or code first
I have an Aspnet MVC 5 project in which I will use Owin and Identity, I needed to customize Identity (attributes and relations) to meet my needs, but I already have all the tables of the database…
-
4
votes1
answer39
viewsHow to set default properties for variables that start with specific text?
Is there any way to define the properties of a variable as default by the initials of the variables? Something like public string obsUsuario { get; set; }, all of which start with Obs by default the…
-
4
votes2
answers254
viewsCRUD with images , working with Httppostedfilebase and byte[]
We are using Entityframework with Codefirst and Database Postgresql. There are some tables that should save images, and the POCO classes are referenced as byte array. Up to that point all quiet. I…
-
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
answer849
viewsHow to disable Migrations from an EF6 project?
Hello! I have a class library with models using Code First and enabled Migrations with the command "enable-Migrations" in PMC to test and works very well. As I am at the beginning of the model…
-
3
votes1
answer383
viewsError in relation statement 1 to 1 in EF with code-first and attributes!
I have the following classes where I want to make a relationship 1 to 1: User: [Table("Usuario")] public class Usuario { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id {…
-
3
votes1
answer226
viewsWhy are relationships in the Entity Framework code first pointed with Icollection<T>?
Why are relationships in the Entity Framework code first pointed to with Icollection? What is the best instantiation(?) for the property in common cases? List? Using the virtual keyword is only to…
-
3
votes1
answer168
viewsMysql.Entity version compatible with Mysql 5.6
What versions of: Mysql.Data Mysql.Data.Entity EPH Compatible with Mysql version 5.6?
-
3
votes1
answer238
viewsPerformance in string filter queries vs foreign key
I’m working on a project Asp.Net MVC 5 using code first and all entities have a property called UserId of the kind string. When I will make queries filtering by a certain user(Asp.Net Identity) I do…
-
3
votes0
answers327
viewsEF mapping of Fluent API associative entity
I would like to know how to do a mapping without using ICollection, or may even be using, but would not want the bank to create a class, just to be able to connect the two classes. class Pessoa {…
-
3
votes1
answer1027
viewsCode First Migrations Mysql - Specify the '-Verbose' flag to view the SQL statements being Applied to the target database
I am creating a web application in C# and because of the hosting server, the database is in Mysql. Then I installed Mysql.Data.Entity, EF6, enabled Migrations, added the Migrations class, but when…
-
3
votes1
answer672
viewsDbupdateexception exception
I am trying to study EF with Code First. I am getting this exception on SaveChanges() An unhandled Exception of type System.Data.Entity.Infrastructure.Dbupdateexception occurred in…
-
3
votes1
answer95
viewsDoubt when configuring entities relationship
In a hypothesis, I have an entity to register addresses: public class Endereco { [Key] public int EnderecoId { get; set; } public string TipoLogradouro { get; set; } public string Logradouro { get;…
-
3
votes1
answer132
viewsHow to simplify declaration of types with Entity Frameowrk?
I have some tables with several fields of type datetime, and for all of them I need to create a validation in Onmodelcreating() for this type, IE, I need to define .HasColumnType("datetime");, my…
-
3
votes2
answers343
viewsMany to Many with Fluent API
I’m doing a mapping with Fluent API and I came up with a question on how I should do the mapping very much. For example, I have the classes below. public partial class Territories { public…
-
3
votes1
answer26
viewsError running Updade-Database command
When executing the command Update-Database Package Manager Console gets the following error: Value cannot be null. Parameter name: entitySet I have only one model in the project for now public class…
c# asp.net-mvc entity-framework asp.net-web-api code-firstasked 7 years, 1 month ago Renan Carlos 1,594 -
2
votes1
answer235
viewsCan the automatically generated . mdf database in App_data be used in production?
The automatically generated database within the App_data folder in projects Asp.Net MVC and Web-Api can be used in production or is a test basis only?
-
2
votes1
answer369
viewsOne-To-Many relation with explicit Foreign key name
I’m performing a simple mapping of one-to-Many via Fluent API specifying which column is used in the mapping, however EF "ignores" the configuration and continues using the name default. Mappings:…
-
2
votes1
answer138
viewsHow NOT to cascade delete records with 1-n relationship using Entity Framework?
I have a table Menu that may have many Categories and these Categories may have only one Menu: public class Menu { public int Id { get; set; } public string Name { get; set; } public virtual…
-
2
votes1
answer69
viewsDoubt in the study of the Code First development approach
Galera I am studying the development approaches used in Entity Framework 6 the approaches Model First and Database First found good content easily on the internet and I was able to understand , but…
-
2
votes1
answer721
viewsEntity Framework associative table mapping
Abstracting some details I have these classes: public class Department: Entitie { public string Description { get; private set; } public DateTime CreateDate { get; private set; } public virtual…
-
2
votes1
answer271
viewsEntity framework Many-to-Many Ientitychangetracker error. How to resolve?
I have a Many-to-Many relationship and my tables are correct about the relationship in the database. The problem is that my insertion works perfectly when you don’t use an existing entity in the…
-
2
votes1
answer867
viewsUpdate multiple databases using code first without using console
Good afternoon, you guys. I have an application that each client has their database and I am using the code first. To update I am always running in hand the command update-database -force in the…
-
2
votes2
answers147
viewsHow do I migrate Code First without deleting data from the table attribute?
I need to change the attribute name of Heaviness for Pesoproduct, this is the code that is generated after executing the command add-Migration: namespace Web.Dominio.Migrations { using System; using…
-
2
votes1
answer71
viewsCodefirst Entity Framework database, 1-0.. 1, 1-N
I have 3 tables and need to relate them via code (Code First) I would like to know how to do this. I already have the following table codes: Tbhistoricoanalogic using System; using…
-
2
votes1
answer47
viewserror left Join Linq
I cannot access the methods of a daughter class that was created using database first: namespace Dados { using System; using System.Collections.Generic; public partial class pessoa { public pessoa()…
-
2
votes1
answer1998
viewsDependency Injection - Error: Invalidoperationexception: Unable to resolve service for type
Friends, once again I come to you for help. When trying to call an Action from my Controller I am getting the problem described below: An unhandled Exception occurred while Processing the request.…
-
1
votes1
answer97
viewsHow do you model 1x0 relations. 1 (optional one-to-one) in the Entity Framework Code First?
When an Entity CAN have one (and only one) instance of another Entity, but the second entity must have the first, as the Entities modeling is done?
-
1
votes1
answer203
viewsHow to publish . mdf database in Azure SQL Dabases?
I have a solution with a project Asp.Net MVC 5 and I’m using Code First and Migrations to update the database .mdf automatically generated in the App_data folder. How do I put this .mdf in the Azure…
-
1
votes1
answer154
viewsMysql with Entity framework Code First ID skipping 10
I’m setting up a Mysql in the Azure for an application I’m working on, however while saving my records to identity column is increasing by 10 by 10. This would be an Entity adjustable setting or an…
-
1
votes1
answer99
viewsCode First One to Many
My setting: public class AlunoAvaliacao { public int AlunoAvaliacaoID { get; set; } public DateTime Inicio { get; set; } public DateTime? Fim { get; set; } public virtual int AvaliacaoID { get; set;…
-
1
votes0
answers64
viewsHow to improve the loading of related entities using Linqkit?
Hi, I’m using Linqkit To stack "Expression Predicates", I need to do a "foreach" to load the related entities and this is being very expensive for application because to load 1000 records is taking…
-
1
votes1
answer1626
viewsC# decimal field in the form
Simple question: I have a currency decimal field on my model. It happens that when I insert a decimal value in the form field, it arrives as integer in the Controller: Example: Value of KM Wheelset:…
-
1
votes2
answers231
viewsEF 6 Code First: Decimal field gives error when trying to save
You guys, good morning. I have a class that has a decimal field where I keep the price. So far so good. When it is displayed in the /Edit/ page, also ta beauty. But here’s the problem: 1 - The MVC…
c# asp.net-mvc entity-framework asp.net-mvc-4 code-firstasked 9 years, 5 months ago Luiz Felipe 456