entity-framework-4.1

Disconnected Behavior of Entity Framework when Updating Object Graph

橙三吉。 提交于 2019-12-02 05:12:06
问题 I'm currently working with a project that use following technologies. ASP.net MVC - presentation Layer Data Service Layer - (WCF) Data Transfer Objects(DTO) Layer with Auto Mapper Domain Layer (POCO, Code First Entity Framework) Repository Layer + Entity Framework 4.3 + DbContext. We use DTOs to convert Domain objects vice versa using auto mapper and sent to front end by using WCF Service. Also, we are creating per request based DBContext in WCF layer for each request and our WCF service

Entity Framework, trigger mechanism for before update values

北战南征 提交于 2019-12-02 04:56:00
问题 Is there anyway in EF to have before update values of object? e.g. When entity object let's say User is saved, i would like to know for logging purpose before update User object values. Thanks, 回答1: If you work with ObjectContext (edmx) you can subscribe to the SavingChanges event. context.SavingChanges += context_SavingChanges; This gives access to the original and current values when SaveChanges() is executed: private void context_SavingChanges (object sender, EventArgs e) { ObjectContext

What's the correct way to use ObjectResult with input parameters to StoredProcedure in Entity Framework? (Output mapped to Complex Type Property)

社会主义新天地 提交于 2019-12-02 04:32:14
I have several listboxes which have a SelectedItem property I intend to use as input parameters to execute my stored procedure in Entity Framework. I now realize my only hope for easily returning entity objects as the result of my Stored Procedure is to map the Stored Procedure (or Function Import) to a complex type which matches the output. (Used Julie Lerman's post here to make this decision.) However, I need help using ObjectResult with EntityFramework to capture my listbox SelectedItem properties and feed them to the Stored Procedure (and thus output my complex type entities). Is anyone

C# Entity Framework 4.1 Lambda Include - only select specific included values

℡╲_俬逩灬. 提交于 2019-12-02 04:22:33
问题 I'm doing a lambda select on EF4.1, including another related DBSet in my current statement. return dbEntity.GameTypes.Include(a => a.Draws) .Where(d => d.IsActive == true ) .ToList(); I've got two classes: //simplified versions of the classes public class GameType { public Nullable<bool> IsActive { get; set; } public virtual ICollection<Draw> Draws { get; set; } } public class Draw { public int DrawID { get; set; } public int GameTypeID { get; set; } public System.DateTime DrawDate { get;

How to work with navigation properties (/foreign keys) in ASP.NET MVC 3 and EF 4.1 code first

别等时光非礼了梦想. 提交于 2019-12-02 03:49:28
I started testing a "workflow" with EF code first. First, I created class diagram. Designed few classes - you can see class diagram here Then I used EF Code First, created EntsContext.. public class EntsContext : DbContext { public DbSet<Project> Projects { get; set; } public DbSet<Phase> Phases { get; set; } public DbSet<Iteration> Iterations { get; set; } public DbSet<Task> Tasks { get; set; } public DbSet<Member> Members { get; set; } } Next step was creating a ProjectController (ASP.NET MVC3) with simple action: public ActionResult Index() { using (var db = new EntsContext()) { return View

Conditional Validation on MVC3 Model Class

大憨熊 提交于 2019-12-02 03:30:56
I'm using Entity Framework and a Model class, DonationForm, wrapped by a view model class "CreateDonationForm". In keeping with the DRY principle, I have added the validation annotations on the Model class (not the just the view model), so that they will be reusable. However, not all of the properties on the class will always be used (some are in fact mutually exclusive). For example when a particular phone number property is relevant, I want to make it conform to a Regex annotation and be Required. But in a different situation I want to be able to get away with submitting (and persiting to

How do I use Linq and Entity Framework to join two jointables?

落爺英雄遲暮 提交于 2019-12-02 03:30:28
问题 I have a very normalized database, and I'm trying to join two join tables together. My goal is to only show documents that the user has permission to. I'm using Entity Framework, and have several foreign keys set up for the following tables: Relationships (Foreign Keys) Users --------------------------------------------- | UserGroupMembership (UserID, GroupID) | | Groups ----- -------------------------------------------------| | | |---------------------------------------------------------| |

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

社会主义新天地 提交于 2019-12-02 01:40:55
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<SuperHuman> SuperHumans { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) {

Lazy load for nonnavigation property in EF 4.1

馋奶兔 提交于 2019-12-02 00:20:14
问题 Is there a simple solution to make lazy load for nonnavigation property in the EF 4.1? For example, for byte array. 回答1: No EF doesn't provide lazy loading for scalar and complex properties. The trick is to use table splitting where data from single table are mapped into two entities related with one-to-one relation. One entity is the principal and it contains navigation property to the dependent and because of that you can use lazy loading. Here is the question with link how to do it in EDMX

Lazy load for nonnavigation property in EF 4.1

时光毁灭记忆、已成空白 提交于 2019-12-01 21:19:15
Is there a simple solution to make lazy load for nonnavigation property in the EF 4.1? For example, for byte array. Ladislav Mrnka No EF doesn't provide lazy loading for scalar and complex properties. The trick is to use table splitting where data from single table are mapped into two entities related with one-to-one relation. One entity is the principal and it contains navigation property to the dependent and because of that you can use lazy loading. Here is the question with link how to do it in EDMX and the answer provides solution for mapping in code-first (comments contains link to