How to make Entity Framework 5.0 use an in-memory persistence DbContext instead of accessing the database.

If you want to switch between in-memory stub data and a database during runtime with Entity Framework 5.0, you have several options, some of them are: – Using a second level cache mechanism like http://www.codeproject.com/Articles/435142/Entity-Framework-Second-Level-Caching-with-DbConte , filling the cache before use and setting the expiration time to infinite. – Creating …

How to update an entity in the database, when state tracking is disabled in Entity Framework 4.3

When you disable state tracking in Entity Framework 4.3, for performance improvements (and you know what you’re doing ), by setting: DbContext.Configuration.AutoDetectChangesEnabled = false , then you are responsible for your own state tracking on entities.   The process of updating an entity, involves 3 steps: 1. Setting the EntityState …

How to update a entity in EF 4.2, when using Configuration.AutoDetectChangesEnabled = false.

  When you use DbContext.Configuration.AutoDetectChangesEnabled = false to improve performance, then there will be no automatically state tracking (this is what’s causing the performance penalty). To update a entity in the database, including it’s releated entities (navgiation properties), you should use the Entry function on the DbContext: using System.Data.Entity; using …

How to set the connectionstring at runtime of a dbcontext in Entity Framework 4.2

If you want to set the connectionstring for a dbcontext, when using EntityFramework 4.2, just create a partial class for the specific dbcontext and add a constructor that call’s de dbcontext constructor with connectionstring. Now you can instantiate MyDatabaseEntities with a connectionstring.   public partial class MyDatabaseEntities { public MyDatabaseEntities(string …

How to list all entity names / table names from your Entity Framework model in Silverlight 4 and RIA services

If you want to list all entity names / table names from your Entity Framework model (*.edmx) in Silverlight 4, use a RIA Invoke operation:   using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Metadata.Edm; using System.ServiceModel.DomainServices.Server; namespace Research.Web { public partial class ResearchDomainService { /// <summary> /// Get …