Wednesday, January 29, 2014

Improving bulk insert performance in Entity framework

Sometimes Entity Framework will have poor performance when inserting records. A possible workaround is to set the following flags:
yourContext.Configuration.AutoDetectChangesEnabled = false;
yourContext.Configuration.ValidateOnSaveEnabled = false;
This should be done before the calls to 'AddObject'.   In my case, this reduced the time a piece of code took to process 2,000 records from 8 minutes down to about 10 seconds.

This fix requires more research to determine if there are side-effects to setting these.  If this is a shared context, then the flags should be set back to their original values after 'SaveChanges' has been called.

Note that this only works with DBContext,and not ObjectContext

Monday, January 6, 2014

Moving a Repository from SVN to Git on VisualStudio.com


  1. Create a new folder.
  2. Launch a Git Bash prompt and navigate to this folder.
  3. Use git to clone the SVN repository to this folder. 
    1. git svn clone http://svn/repo/here/trunk   (Taken from http://stackoverflow.com/a/79178/224531)
    2. This may take a while if there is a lot of history.  But the end result is a stand-alone Git repo with all the history in it. 
  4. Go the TFS site (visualstudio.com), and create a new project using Git as the source control. 
  5. After this is created open the project and click on the 'Code' menu.
  6. It should show that the repository is empty.  Follow the steps on this page, using the Bash command prompt, to attach the local repo to this new origin, and push the changes to the TFS site. 

Friday, January 3, 2014

Fixing 500 Errors with IISExpress

When an app throws 500 errors in IIS Express with no additional debugging information, try the following:
  • Close VS Studio - solution set with IISExpress
  • Go to: /Document/IISExpress/config/ in your profile
  • Rename or delete applicationhost.config
  • Open your solution in VS Studio
  • A dialog may fire up from IISExpress - this will set a fresh config.
  • try to run your web app.

Wednesday, November 20, 2013

Fixing Screen Resolution in VirtualBox

Sometimes a virtual pc in VirtualBox will refuse to take up the whole screen.  Even in Full-Screen mode, it will insist on showing things in a 1024x768 resolution.   To fix this, you need to open a command prompt and run one of the following from c:\Program Files\Oracle\VirtualBox .   This was taken from section 9.8.2 of the VirtualBox manual

VBoxManage setextradata global GUI/MaxGuestResolution any
will remove all limits on guest resolutions.
VBoxManage setextradata global GUI/MaxGuestResolution >width,height<
manually specifies a maximum resolution.
VBoxManage setextradata global GUI/MaxGuestResolution auto
restores the default settings. Note that these settings apply globally to all guest systems, not just to a single machine.

Tuesday, September 24, 2013

EF Empty Strings in Non-Nullable Fields

When using Entity Framework, sometimes it is desirable to have non-nullable string fields.  The problem is that if the user leaves the field blank, EF will complain that a value is required in the field.   To fix this, create a metadata class for the entity you are working with.   Then decorate the field with this attribute:
[DisplayFormat(ConvertEmptyStringToNull=false)]
This will allow you to save the entity with an empty string in this field.

Monday, September 23, 2013

Auto entering credentials in Git

Any time you do a Fetch or a Push to a secure Git repository, you will be asked for your username and password.  To have these credentials auto-entered, do the following:


  1. Download got-credential-winstore. https://gitcredentialstore.codeplex.com/
  2. Put it in a folder where you will keep it permanently.
  3. Run it with the -i option to specify the Git location (not 100% sure this step is necessary.
  4. To use this in TortoiseGit, go to Settings/Credentials. 
  5. Select 'wincred - this repository only'

Saturday, February 23, 2013

Switch/Select Case Statement in Reporting Services

This is how you do a  Switch or Select Case statement in Reporting Services.  This would go in the Expression field of a field.    Note that the 'Else' condition is implemented by using the 'True' item as the last line in the statement.

 = switch (  
      Fields!Problems.Value = 1, "Units cannot be converted.",  
      Fields!Problems.Value = 2, "Price is zero.",  
      Fields!Problems.Value = 4, "Quantity is zero.",  
      True, Fields!Problems.Value  
 )