Migrations Commands

View Script: Update-Database -Script -SourceMigration:0


Enables Code First Migrations in a project.

Enable-Migrations [-ContextTypeName ] [-EnableAutomaticMigrations]
[-MigrationsDirectory ] [-ProjectName ] [-StartUpProjectName ]
[-ContextProjectName ] [-ConnectionStringName ] [-Force]
[-ContextAssemblyName ] [-AppDomainBaseDirectory ] []

Enable-Migrations [-ContextTypeName ] [-EnableAutomaticMigrations]
[-MigrationsDirectory ] [-ProjectName ] [-StartUpProjectName ]
[-ContextProjectName ] -ConnectionString
-ConnectionProviderName [-Force] [-ContextAssemblyName ]
[-AppDomainBaseDirectory ] []
Enables Migrations by scaffolding a migrations configuration class in the project. If the target database was created by an initializer, an initial migration will be created (unless automatic migrations are enabled via the EnableAutomaticMigrations parameter).


Scaffolds a migration script for any pending model changes.

Add-Migration [-Name] [-Force] [-ProjectName ] [-StartUpProjectName ]
[-ConfigurationTypeName ] [-ConnectionStringName ] [-IgnoreChanges]
[-AppDomainBaseDirectory ] []

Add-Migration [-Name] [-Force] [-ProjectName ] [-StartUpProjectName ]
[-ConfigurationTypeName ] -ConnectionString -ConnectionProviderName
[-IgnoreChanges] [-AppDomainBaseDirectory ] []


Applies any pending migrations to the database.

Update-Database [-SourceMigration ] [-TargetMigration ] [-Script] [-Force]
[-ProjectName ] [-StartUpProjectName ] [-ConfigurationTypeName ]
[-ConnectionStringName ] [-AppDomainBaseDirectory ] []

Update-Database [-SourceMigration ] [-TargetMigration ] [-Script] [-Force]
[-ProjectName ] [-StartUpProjectName ] [-ConfigurationTypeName ]
-ConnectionString -ConnectionProviderName
[-AppDomainBaseDirectory ] []
Updates the database to the current model by applying pending migrations.

Only valid with -Script. Specifies the name of a particular migration to use as the update’s starting point. If ommitted, the last applied migration in the database will be used.

Specifies the name of a particular migration to update the database to. If ommitted, the current model will be used.

Generate a SQL script rather than executing the pending changes directly.

Specifies that data loss is acceptable during automatic migration of the database.

Specifies the project that contains the migration configuration type to be used. If ommitted, the default project selected in package manager console is used.

Specifies the configuration file to use for named connection strings. If omitted, the specified project’s configuration file is used.

Specifies the migrations configuration to use. If omitted, migrations will attempt to locate a single migrations configuration type in the target project.

Specifies the name of a connection string to use from the application’s configuration file.

Specifies the the connection string to use. If omitted, the context’s default connection will be used.

Specifies the provider invariant name of the connection string.

Specifies the directory to use for the app-domain that is used for running Migrations code such that the app-domain is able to find all required assemblies. This is an advanced option that should only be needed if the solution contains several projects such that the assemblies needed for the context and configuration are not all referenced from either the project containing the context or the project containing the migrations.


Project Description

This is a Windows 8 HTML/JS project with the express goal of demonstrating simple development concepts for the Windows 8 platform. You may learn some stuff about end-to-end app architecture by looking at the source code of codeShow, but the primary goal of the project is to help you learn discrete programming tasks such as accessing the camera, implementing an asymmetric ListView, or handling errors look to codeShow.
To see what’s new with codeShow, visit the news page.




Removing the XML Formatter from ASPNET Web API Applications, to Json/p result

    ///In filters register:
    // This method allows the client to override their browser's HTTP Accept header by putting a value in the querystring.
    GlobalConfiguration.Configuration.Filters.Add(new FormattingOverrideFilterAttribute(formatPreferenceOverride: "application/json", clearOtherPreferredMediaTypes: true));

public class FormattingOverrideFilterAttribute : ActionFilterAttribute{
    /// <summary>
    /// Allows overriding the Accept header by querystring or server preference.
    /// </summary>
    /// <param name="formatPreferenceOverride">If defined, this mime type will be injected into the Accept header of every request.</param>
    /// <param name="newQuality">Optional, The quality setting for this media type. Should be between 1 and 0.</param>
    /// <param name="clearOtherPreferredMediaTypes">If true, will remove all other media types from the Accept header.</param>
    public FormattingOverrideFilterAttribute(string formatPreferenceOverride = null, double? newQuality = null, bool clearOtherPreferredMediaTypes = false) : base() {
        NewQualityValue = newQuality;
        FormatPreferenceOverride = formatPreferenceOverride;
        ClearOtherPreferredMediaTypes = clearOtherPreferredMediaTypes;

    public double? NewQualityValue { get; set; }
    public string FormatPreferenceOverride { get; set; }
    public bool ClearOtherPreferredMediaTypes { get; set; }

    public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) {
        var qs = actionContext.Request.RequestUri.ParseQueryString();

        var requestedMediaType = (qs["f"] ?? qs["format"] ?? FormatPreferenceOverride ?? String.Empty).ToLower();

        switch (requestedMediaType) {
            case "xml":
            case "x":
                requestedMediaType = "application/xml";
            case "j":
            case "js":
            case "json":
                requestedMediaType = "application/json";

        if (String.IsNullOrEmpty(requestedMediaType))
            return; // No action is necessary because no override was requested.

        var acceptHeaders = actionContext.Request.Headers.Accept;
        MediaTypeWithQualityHeaderValue header = null;

        if (ClearOtherPreferredMediaTypes) {
            var newAcceptHeaders = acceptHeaders.Where(h => h.MediaType == requestedMediaType || h.MediaType == "*/*").ToList();

        header = acceptHeaders.FirstOrDefault(h => h.MediaType == requestedMediaType);
        if (header == null) {
            header = new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(requestedMediaType);

        System.Diagnostics.Debug.WriteLine("Overidding HttpAccept header for format preference.");
        header.Quality = NewQualityValue;


Best—> http://weblog.west-wind.com/posts/2012/Apr/02/Creating-a-JSONP-Formatter-for-ASPNET-Web-API

Another…. ->http://weblog.west-wind.com/posts/2012/Mar/09/Removing-the-XML-Formatter-from-ASPNET-Web-API-Applications

Rotativa, Extremely easy way to create Pdf files from Asp.net MVC.


Extremely easy way to create Pdf files from Asp.net MVC.


public ActionResult PrintIndex()
    return new ActionAsPdf("Index", new { name = "Giorgio" }) { FileName = "Test.pdf" };
public ActionResult Index(string name) 
    ViewBag.Message = string.Format("Hello {0} to ASP.NET MVC!", name); 
    return View(); 

ViewAsPdf now available. It enables you to render a view as pdf in just one move, thanks to scoorf

public ActionResult TestViewWithModel(string id)
    var model = new TestViewModel {DocTitle = id, DocContent = "This is a test"};
    return new ViewAsPdf(model);

Also available a RouteAsPdf, UrlAsPdf and ViewAsPdf ActionResult.

It generates Pdf also from authorized actions (web forms authentication).