Questions tagged as 'entity-framework-6'

1
answer

bring menus and active submenus C #

I have to make a query by the menu that I have to bring only the active submenus, see my code. return context.Set<Menu>().Include("MenuGroups") .Where(x => x.Id == id && x.MenuGroups.Any(z => z.Active))...
asked by 30.01.2017 / 16:02
2
answers

How to create 1-N relationship in class with more than one property and even subtype?

I have the following class structure, unconventional but it's in the template I need to solve my problem: Tree: public class Arvore { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; }...
asked by 18.08.2014 / 16:28
2
answers

How to insert Entities, related to others already existing, in the EntityFramework?

In case supposing an "EntityA" entity that references an entity "EntityB", I want to save it, but referencing an existing entity B ex: EntidadeA a = new EntidadeA(); EntidadeB b = new EntidadeB(); b.Id = 5;// id de entidade existente no banco...
asked by 08.12.2014 / 18:48
1
answer

Use of Time with EF 6

I have a class with the following property. public TimeSpan TempoIdeal { get; set; } Estou atribuindo esta propriedade com TempoIdeal = new TimeSpan(days: 3, hours: 15, minutes:10, seconds: 0); When trying to insert I g...
asked by 23.06.2016 / 05:39
1
answer

Error saving field of type DateTime

I am setting up an example of Code First, but at the time of saving a field of type DateTime in the database I get the following error    Converting a datetime2 data type to a datetime data type   resulted in a value out of range. \ r \ nThe...
asked by 23.11.2016 / 19:58
1
answer

Best practices when filtering a query with EntityFramework

I have a method in web api that receives a model from a search form and according to its values, it starts to filter the result of this search, as shown below. public HttpResponseMessage Buscar([FromBody]BuscarModel model) { C...
asked by 04.01.2016 / 19:44
1
answer

Entity Framework - Deleting object with relationship

I have a question for understanding the behavior of Entity. Because when I pass null to a property the Entity should not "clean" the relationship in the bank? My Model: public partial class Ocorrencia { [Key] public int id {...
asked by 29.03.2017 / 19:29
1
answer

Error when connecting PostgreSQL to the Entity Framework

I'm trying to connect to EF in Postgresql. You are running the following message:   An unhandled exception of type   'System.Configuration.ConfigurationErrorsException' occurred in   System.Configuration.dll       Additional information: An...
asked by 24.03.2017 / 02:11
1
answer

Error adding migration with Migrations

I'm trying to add a migration and migration returns the following message:    The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when yo...
asked by 16.09.2015 / 01:07
1
answer

Create unique attribute beyond the Primary Key in code-first

I am creating a Logradouro table where the CEP field is not the primary key, but must be unique. How do I do this using code-first in Entity 6.0 ? To create primary key I use the HasKey method: ToTable("Logradouros...
asked by 16.06.2016 / 21:27