Refactor rename on LINQ to SQL Classes

This is a quick, dirty work around to renaming the properties of the LINQ to SQL classes. Say you have a simple DBML class you want to rename.

image

Simple enough right? Just click in there and edit the WidgetName to Name right? Wrong! You have code like this.

public Widget CreateNewWidget(string name, string description)
{
    return new Widget {
        WidgetDescription = description,
        WidgetName = name
    };
}

You’re going to abandon all those calls to WidgetName and do a search and replace refactor. That sucks. So rename it to WidgetName2 for now and let all the references break.

image

That breaks our code.

image

Fine for now. Create a partial class for the Widget.cs and add our WidgetName back in

public partial class Widget
{
    public string WidgetName { get; set; }
}

Use ReSharper to rename that property to name.

image

Then delete the partial class, or property and rename the property in the DBML to Name.

Done.

2 Comments so far

  1. Pr0fess0rX on January 3rd, 2010

    Thanks, Is it possible to know what is you visual studio theme name? or can you export it so i can download it?

    Kind Regards

  2. mark on January 3rd, 2010

    I have a blog post that talks about it http://fooberry.com/2009/04/23/dark-ide-colors-v20/ and http://fooberry.com/2008/10/15/join-the-dark-side-of-the-force/ . The Monaco font is really nice and I very easy to read.

Leave a Reply