How can I stop Entity Framework 5 migrations adding dbo. into key names?

You can customize the generated code by sub-classing the CSharpMigrationCodeGenerator class: class MyCodeGenerator : CSharpMigrationCodeGenerator { protected override void Generate( DropIndexOperation dropIndexOperation, IndentedTextWriter writer) { dropIndexOperation.Table = StripDbo(dropIndexOperation.Table); base.Generate(dropIndexOperation, writer); } // TODO: Override other Generate overloads that involve table names private string StripDbo(string table) { if (table.StartsWith(“dbo.”)) { return table.Substring(4); } return table; } … Read more

Ignore TransactionScope for specific query

If you wrap your log call inside of another transaction scope with the suppress option enabled, transaction scope will not be used. public override int SaveChanges() { try { return base.SaveChanges(); } catch (Exception ex) { using (var scope = new TransactionScope(TransactionScopeOption.Suppress)) { LogRepo.Log(message); // stuff to log from the context } throw; } }

System.Data.Spatial DbGeography.Distance units?

Several articles seem to agree on meters being used in 4326 as the unit of distance. WGS 84 is done in meters as well, which is probably why this uses meters. http://blogs.msdn.com/b/adonet/archive/2011/06/30/walkthrough-spatial-june-ctp.aspx http://www.jasonfollas.com/blog/archive/2011/07/20/entity-framework-spatial-first-look.aspx http://blog.simplecode.eu/post/DistancesWithDbGeographyAndDbGeometry

How do you downgrade a Entity Framework 5 migration in Visual Studio 2012?

After almost giving up with researching on Google I managed to find this quote from here: http://msdn.microsoft.com/en-gb/data/jj591621.aspx#specific Which Specifies: Let’s say we want to migrate our database to the state it was in after running our AddBlogUrl migration. We can use the –TargetMigration switch to downgrade to this migration. Run the Update-Database –TargetMigration: AddBlogUrl command … Read more

Adding CreatedDate to an entity using Entity Framework 5 Code First

Here is how I did it: [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public DateTime CreatedDate{ get; set; } in my migration’s Up() method: AddColumn(“Agents”, “CreatedDate”, n => n.DateTime(nullable: false, defaultValueSql: “GETUTCDATE()”));