Monday, November 23, 2015

See 'EntityValidationErrors' property for more details

This is an annoying error.  It generally occurs when calling SaveContext in EF.  It means that there was something wrong with the data you were trying to Save, but it's not going to tell you what exactly.  

Fortunately, there is an easy fix if you are running in the debugger.  To get EF to cough up the EntityValidationErrors, simply create a new watch with the following:

((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors

Wednesday, January 14, 2015

Git: Pulling in tags from remote

When working with a Git repository, you may find that you don't have the latest set of tags, or that a tag has moved, and your local repository does not reflect the update.   To update the tags in your local repository to reflect the remote, do the following:
git fetch --tags
This will pull down all tags on the current branch.

Wednesday, December 31, 2014

Alert for Bootstrap

Do this if you want a Bootstrap alert at the top of your page.  Swap out 'alert-warning' for 'alert-error' if you want red instead of yellow.
 @if(Model.Message != null){  
      <div class="alert alert-warning">  
           <button type="button" class="close" data-dismiss="alert">&times;</button>  
           @Model.Message  
      </div>  
 }  

Delete a Remote Git Branch

To delete a branch from the server, do the following:
git push origin --delete serverfix

Saturday, December 27, 2014

File changes aren't ignored even when in the .gitignore file

If Git insists on checking in changes to a file even when the .gitignore file seems like it should be excluded, it is probably because the file is already in the repository.  Git will not ignore a file if it has already been committed.

To resolve this, open a Bash prompt in the root folder of the repository.   ( A shortcut for this in SourceTree is to click on the 'Actions/Open in Terminal' menu.   Run the following:
git rm --cached FolderName/MyFileName.ext
Then commit the change and push it up, and it should ignore the file from then on (assuming your .gitignore was correct to begin with).   Note that this will leave the file as is in your source folder.

Tuesday, December 9, 2014

Call via HTTPClient to an SSL endpoint without a valid certificate

This isn't always a good idea, but sometimes you have to call an http endpoint using that has an SSL certificate that is not valid.  To allow the connection and disregard the certificate error, you can do something like the following:

 using (var client = new HttpClient(new HttpClientHandler()));  
 {  
   // this is the line that will ignore the certificate issues.  
   ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };  
   var response = taskClient.GetAsync(uri).Result;  
 }  

Wednesday, September 17, 2014

Missing Indices in SQL Server

Run the following to show possible missing indices in SQL Server.  Use this information carefully!!!  Do your own evaluation to determine if you really need any of the indices this suggests.  This is only a recommendation.

 SELECT  
 mid.statement  
  ,migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) AS improvement_measure,OBJECT_NAME(mid.Object_id),  
  'CREATE INDEX [missing_index_' + CONVERT (VARCHAR, mig.index_group_handle) + '_' + CONVERT (VARCHAR, mid.index_handle)  
  + '_' + LEFT (PARSENAME(mid.statement, 1), 32) + ']'  
  + ' ON ' + mid.statement  
  + ' (' + ISNULL (mid.equality_columns,'')  
   + CASE WHEN mid.equality_columns IS NOT NULL AND mid.inequality_columns IS NOT NULL THEN ',' ELSE '' END  
   + ISNULL (mid.inequality_columns, '')  
  + ')'  
  + ISNULL (' INCLUDE (' + mid.included_columns + ')', '') AS create_index_statement,  
  migs.*, mid.database_id, mid.[object_id]  
 FROM sys.dm_db_missing_index_groups mig  
 INNER JOIN sys.dm_db_missing_index_group_stats migs ON migs.group_handle = mig.index_group_handle  
 INNER JOIN sys.dm_db_missing_index_details mid ON mig.index_handle = mid.index_handle  
 WHERE migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) > 10  
 ORDER BY migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) DESC