entity-framework-4.1

Entity Framework - Is there a way to automatically eager-load child entities without Include()?

不打扰是莪最后的温柔 提交于 2020-06-30 03:56:57
问题 Is there a way to decorate your POCO classes to automatically eager-load child entities without having to use Include() every time you load them? Say I have a Class Car, with Complex-typed Properties for Wheels, Doors, Engine, Bumper, Windows, Exhaust, etc. And in my app I need to load my car from my DbContext 20 different places with different queries, etc. I don't want to have to specify that I want to include all of the properties every time I want to load my car. I want to say List<Car>

Context lifetime management in repository and unit of work pattern

人盡茶涼 提交于 2020-02-08 07:24:31
问题 I have a repositories implemented with unitOfWork pattern and share a context. i have a service layer on top of these repositories. which has multiple services. When ever i instantiate a service class - unitOfWork instance is created. But many times these services methods call each other and sometimes operate on common session objects. Which causes a problem of the same entity being tracked by multiple contexts or more specifically - An entity object cannot be referenced by multiple instances

Proxy's First Navigation Property is null when Seeding EF 4.1

↘锁芯ラ 提交于 2020-02-02 13:06:13
问题 When Initializer.Seed() uses DbContext.DbSet.Find() to set the navigation properties for a new Proxy, it correctly assigns the FK's to the Proxy, but the first navigation property is always null when I break on SaveChanges() and inspect the Proxy. Does anyone know why it does this? (Sorry, I can't post a screenshot of the locals window.) Model public class Thing : Base { public virtual Nullable<int> Option1ID { get; set; } public virtual Option1 Option1 { get; set; } public virtual Nullable

Why is MVC3 not scaffolding my foreign key columns

泄露秘密 提交于 2020-02-01 08:17:21
问题 I'm trying to use MVC 3 with EF 4.1 using code first and am following Scott Guthries tutorial http://weblogs.asp.net/scottgu/archive/2011/05/05/ef-code-first-and-data-scaffolding-with-the-asp-net-mvc-3-tools-update.aspx. The issue I'm having is that when I create the products controller and the related scaffolded views, there is no "category" column being created in any of the views ("edit", "create", "index" etc), which according to the tutorial should be created. I've traced the reason why

How to generalise access to DbSet<TEntity> members of a DbContext?

旧街凉风 提交于 2020-02-01 03:37:09
问题 I have a DbContext with several of the following type of members: public DbSet<JobLevel> JobLevels { get; set; } public DbSet<Country> Countries { get; set; } public DbSet<Race> Races { get; set; } public DbSet<Language> Languages { get; set; } public DbSet<Title> Titles { get; set; } All these are where T: IdNamePairBase , which has Id and Name members only. I am trying desperately to find a common interface with which to access any of these members, to generalise the following MVC3

EF Code First: Retrieving a base type queries all derived type tables

安稳与你 提交于 2020-01-30 06:49:27
问题 I'm having an odd issue with EF 4.1 Code First where even though I have configured an entity to generate columns for its inherited properties, it still joins to the inherited type's table. Here are my classes: public class Human { public int Id { get; set; } public string Name { get; set; } } public class SuperHuman : Human { public int Id { get; set; } public string Powers { get; set; } } public class MarvelDbContext : DbContext { public DbSet<Human> Humans { get; set; } public DbSet

EF Code First: Retrieving a base type queries all derived type tables

試著忘記壹切 提交于 2020-01-30 06:48:26
问题 I'm having an odd issue with EF 4.1 Code First where even though I have configured an entity to generate columns for its inherited properties, it still joins to the inherited type's table. Here are my classes: public class Human { public int Id { get; set; } public string Name { get; set; } } public class SuperHuman : Human { public int Id { get; set; } public string Powers { get; set; } } public class MarvelDbContext : DbContext { public DbSet<Human> Humans { get; set; } public DbSet

Two Foreign Keys in entity framework for same table

此生再无相见时 提交于 2020-01-25 00:07:14
问题 I have two entities: Municipality and RoadSemgents. Municipality is parent and RoadSegments is a child table. I need to have two foreign Keys in RoadSegments from the same table (Municipality). public class Municipality { [Key] public int ID { get; set; } public string Name { get; set; } } public class RoadSegments { [Key] public int ID { get; set; } //ForeignKeys public int CodeMunicipalityLeft_ID { get; set; } public int CodeMunicipalityRight_ID { get; set; } [ForeignKey(

Entity Framework Many to Many and Eager Loading

丶灬走出姿态 提交于 2020-01-24 08:48:27
问题 I'm using Entity Framework 4.1 with MySql and having a problem with the eager loading of a many to many relationship. A simplified version of the affected tables looks like: CabinCategory - CabinCategoryId CabinGrade - CabinGradeId, CabinCategoryId Deck - DeckId DeckCabinGrades - DeckId, CabinGradeId <--- Join table I'm ultimately trying to access CabinCategory.CabinGrade.Deck I think I've managed to map this successfully using modelBuilder.Entity<CabinGrade>() .HasMany(c => c.Decks)

Entity Framework Many to Many and Eager Loading

只谈情不闲聊 提交于 2020-01-24 08:48:09
问题 I'm using Entity Framework 4.1 with MySql and having a problem with the eager loading of a many to many relationship. A simplified version of the affected tables looks like: CabinCategory - CabinCategoryId CabinGrade - CabinGradeId, CabinCategoryId Deck - DeckId DeckCabinGrades - DeckId, CabinGradeId <--- Join table I'm ultimately trying to access CabinCategory.CabinGrade.Deck I think I've managed to map this successfully using modelBuilder.Entity<CabinGrade>() .HasMany(c => c.Decks)