Using Redgates Sql Compare for Complex Migrations with EF’s CodeFirst

Introduction As many of you know, I’ve been quite the fan of Entity Framework CodeFirst for quite some time.  It does a great job of reducing the number of places I have to change thngs each time I have a database schema change and also brings a ton of type safety along with it.  I’ve posted before about the benefits of the auto migrations features built into CodeFirst, however I have found when I make a lot of changes to my schema, I quickly get an error saying I will have data loss so the CodeFirst Migration will not take place. In my realities, it is just too much time to go through with LINQ and try and make the perfect data migration.  My reality is that I likely only have one or two databases that need sql updates and … Continue Reading

LINQ and “Possible Multiple Enumerations of IEnumerable” Warning / Resharper To the Rescue!

In the most recent version of Resharper 7 from JetBrains, the brilliant team has gone one step above and beyond.  Not only do they show this error which can be quite tricky to both understand and fix, but they now go one step further and offer a fix. For example, look at the below code: var emailDetailInfos = new List<EmailDetailInfo>();using (var db = new SiteDB()){ foreach (var emailDetailId in emailDetailIds) { // first get details about this particular email var emailDetail = db.EmailDetails.FirstOrDefault(a => a.Id == emailDetailId); if (emailDetail != null) { // get all the Details associated including the htmlbody if there is one (that is, images and body) var details = (from ed in … Continue Reading

How To Safely Display Data From ASP.NET TextField Inputs

Let’s say you have a user input field that you want the user to type data into which will be later displayed back to the user.  You don’t want the user putting in their own html or other things (like javascript tags) because that could cause bad things to happen on your page.  The easiest thing to do is to set the page attribute to not do request validation   <%@ Page Title="" Language="C#" MasterPageFile="~/DefaultNoColumns.master" AutoEventWireup="true" ValidateRequest="false" CodeFile="SponsorInformationEdit.aspx.cs" Inherits="SponsorInformationEdit" %> Then, store whatever the user types in the textbox including the nasty … Continue Reading

SqlAzure and a Best Practices way to deal with the Required Retries on Connections

Introduction If you’ve started using SqlAzure for your SqlServer with your Azure application, you’ve probably discovered that you get a reasonable number of connection failures.  The advice from the Azure team is add retry logic to all your connections to SqlAzure. There is a long discussion posted by the Azure team here. The key paragraph states the problem as follows: The Problem One of the things that SQL Azure does to deliver high availability is it sometimes closes connections. SQL Azure does some pretty cool stuff under the covers to minimize the impact, but this is a key difference in SQL Azure development vs. SQL Server development. Basically, what this means is that you must be able to deal with connections … Continue Reading


Get every new post delivered to your Inbox

Join other followers: