Entity Framework Migrations quicklist

I have some simple commands to remember using Entity Framework to scaffold MVC Controllers and Views.

When the Model change, how do I make the Database change?

  1. Enable-Migrations (“Creates database or use existing”)
  2. Add-Migration Initial (“Start to set an Initial point where you work from”)
  3. Update-Database (“Apply it to Database”)
  4. Add-Migration ChangedSomething (“Add a new migration and name it”)

Const vs. readonly

Short “what is …”
Difference between const and readonly in C# language?

Const – Compile time constant
Has to be calculated during compile. Cannot be struct (struct is initialized during runtime with constructor).
Cannot be any reference type (well can be any reference type but forced to be null so, useless).
When referenced in another assembly and the const value is changed + recompiled/redeployed .dll, calling assembly needs to be recompiled. Otherwise the changed value is not picked up by calling assembly.

Readonly – Runtime Constant Reference
Used when a value is calculated during runtime.
Used with value types, struct and reference types.
If readonly value used in another assembly and readonly value is changed + recompile/redeployed .dll then new value is checked at runtime by referencing assembly.

Use const when:
The constant is a compile-time value, AND
The constant’s domain does not change or is limited in scope to a single assembly, class, or method.

And use readonly when:
The constant cannot be determined at compile-time, OR
The constant is a non-string, non-null class, OR
The constant is a struct, OR
The constant is instance-level (instead of static).

Start with GitHub as a .NET developer

So GitHub is a new big thing that most developers should know about. What is GitHub?

“Git is an extremely fast, efficient, distributed version control system ideal for the collaborative development of software.”

This is a summary guide how you start with GitHub for .NET developers.

Go and install msysgit for Windows from http://msysgit.github.com/

During Installation:

All Defaults and line-endings is as-is. When you start and download source code you might have different Line-Endings (MAC/Windows difference) and that can cause problems. Type the commands below to validate, or change settings to false.

Signup on http://github.com for a free account.

Next you need to create SSH files to connect to GitHub.

$ ssh-keygen -t rsa -C “youremail@email.com”

Enter (on filename/location prompt)

Enter passphrase twice…

Done! Now 2 files are created under (“C:\Users\Administrator\.ssh”)

id_rsa – is your PASSWORD (keep it safe)
id_rsa.pub – is for public use, send to friends when needed!

Open id_rsa.pub and copy the long string to

When you have copied you public key information to github.com verify it with:

$ ssh -T git@github.com

Are you sure you want to continue connecting (yes/no)?  yes and you passphrase from before:

When msysgit is installed and verified as above.

Set your global settings as:
$ git config –global user.email “your@email.com”

$ git config –global user.name “Your Name”

To connect using SSH you need “API Token” under Account Settings

$ git config -global github.user YourUserName

$ git config –global github.token 0123456789yourf0123456789token

Create a Repository(Project) on github.com (You can only have public repositories on a free account)

To continue see http://help.github.com/create-a-repo/

Now you should have the basic stuff installed and configured.

You have created a local Repository, the connection to your GitHub repository and can upload source code changes to GitHub.

 

Cheers

https://github.com/settings/ssh

Clear TFS (Team Foundation System) cache in Visual Studio 2008

I encountered a error with workspaces that said: Team Foundation Error The workspace [workspacename];[username] already exists on computer [computername].” This problem is easy to fix.

Go to Startmeny – Programs – Microsoft Visual Studio 2008 – Visual Studio Tools – Visual Studio 2008 Command Prompt

When you get the Prompt open you enter this: ‘tf workspaces /remove:* /server:tfsservername2′

This cleared my Cache and i could create my own workspace and map it to correct folders.