Troubleshooting Circular Dependency by Analyzing Dependency Graphs Generated using Visual Studio 2013 Ultimate Architecture Feature

Visual Studio 2013 Ultimate edition includes modeling tools, such as the Architecture Explorer, which graphically displays projects and classes and the relationships between them. It supports UML activity diagram, component diagram, class diagram, sequence diagram, and use case diagram. This video tutorial shows how to use visualization tools in Visual Studio to understand the dependencies and relationships in your code

What's New In Microsoft Enterprise Library 6 Release | C# Tutorial And Tips

,
This major release of Enterprise Library contains many compelling new features and updates that will make developers and IT professionals more productive. Two new application blocks are:
  • Semantic Logging Application Block.
  • Transient Fault Handling Application Block (this application block was previously a part of the Enterprise Library Integration Pack for Windows Azure; in this release it has been generalized and updated to the latest technologies).
Other major new features include:
  • New programmatic configuration that doesn’t require a container.
  • AsynchronousTraceListenerWrapper for the Logging Application Block, which enables existing listeners to write messages asynchronously.
  • JSON formatter for the Logging Application Block.
The new Unity Application Block includes many improvements:
  • Registration by convention.
  • Support for NetCore (Windows Store apps).
  • Resolving objects of type Lazy<T>.
  • The Unity assembly is now Security Transparent.
  • Support for ASP.NET MVC and ASP.NET Web API.
Note, this release of Enterprise Library retired the following application blocks:
  • Caching Application Block
  • Cryptography Application Block
  • Security Application Block

Components In Microsoft Enterprise Library 6 | C# Tutorial And Tips

,
Microsoft Enterprise Library consists of reusable software components that are designed to assist developers with common enterprise development challenges. It includes a collection of functional application blocks addressing specific cross-cutting concerns such as data access, logging, or validation; and wiring blocks, Unity and the Interception/Policy Injection Application Block, designed to help implement more loosely coupled, testable, and maintainable software systems.
Different applications have different requirements, and you will find that not every application block is useful in every application that you build. Before using an application block, you should have a good understanding of your application requirements and of the scenarios that the application block is designed to address.
Microsoft Enterprise Library 6 contains the following application blocks:
  • Data Access Application Block. Developers can use this application block to incorporate standard database functionality in their applications, including both synchronous and asynchronous data access and returning data in a range of formats.
  • Exception Handling Application Block. Developers and policy makers can use this application block to create a consistent strategy for processing exceptions that occur throughout the architectural layers of enterprise applications.
  • Logging Application Block. Developers can use this application block to include logging functionality for a wide range of logging targets in their applications. This release adds asynchronous logging capabilities.
  • Policy Injection Application Block. Powered by the Interception mechanism built into Unity, this application block can be used to implement interception policies to streamline the implementation of common features, such as logging, caching, exception handling, and validation, across a system.
  • Semantic Logging Application Block. This application block provides a set of destinations (sinks) to persist application events published using a subclass of the EventSource class from the System.Diagnostics.Tracing namespace. Sinks include Windows Azure table storage, SQL Server databases, and flat files with several formats and rolling capabilities. Developers can extend the block by creating custom formatters and sinks. For those sinks that can store structured data, the block preserves the full structure of the event payload in order to facilitate analyzing or processing the logged data. Events can be persisted in-process or collected and persisted out-of-process in a separate service.
  • Transient Fault Handling Application Block. This application block makes on-premises or cloud applications more resilient to transient failures by providing intelligent retry logic mechanisms.
  • Unity Application Block. Developers can use this application block as a lightweight and extensible dependency injection container with support for constructor, property, and method call injection, as well as instance and type interception. This release adds support for Windows Store apps as well as the registration by convention feature to ease the task of configuring Unity.
  • Validation Application Block. Developers can use this application block to create validation rules for business objects that can be used across different layers of their applications.
Enterprise Library also includes a set of core functions for declarative configuration support.

Scenarios To Implement Microsoft Enterprise Library | C# Tutorial And Tips

,
Microsoft released new version of Microsoft Enterprise Library 6. Microsoft Enterprise Library is a collection of application blocks designed to assist developers with common enterprise development challenges. Application blocks are a type of guidance, provided as source code that can be used "as is," extended, or modified by developers for use in their development projects.
Microsoft Enterprise Library can be useful in a variety of situations:

  • Enterprise Library provides sufficient functionality to support many common cross-cutting scenarios that enterprise-level applications must address.
  • Enterprise Library can serve as the basis for a custom library. You can take advantage of the extensibility points incorporated in each application block and extend the application block by adding new providers. You can also modify the source code for the existing application blocks to incorporate new functionality, and even add new application blocks to Enterprise Library. You can either develop extensions for existing application blocks and new application blocks yourself, or you can use extensions and application blocks developed by others.
  • Enterprise Library is designed so that its application blocks can function independently of each other. You need to add only the application blocks that your application will use.
  • Enterprise Library includes the source code and the unit tests for all application blocks. This means you can explore the implementations, modify the application blocks to merge into your existing library, or you can use parts of the Enterprise Library source code in other application blocks or applications that you build.
  • Enterprise Library includes documentation, a reference implementation, and source code. Enterprise Library embodies many design patterns, and demonstrates good architectural and coding techniques. You can use the library as a tool for learning architectural, design, and proven coding practices.

Features Of Power Tools Extension For Visual Studio 2013 | .Net Tips And Tricks

Productivity Power Tools 2013 for Visual Studio 2013 is an extension pack that brings powerful tools for improved developer productivity. With the release of Productivity Power Tools 2013 for Visual Studio 2013 come eleven new powerful features. Some of these features are brand new extensions, while others are improvements to functionality found in previous versions of Productivity Power Tools. In this video we'll introduce you to such new features as quick tasks, recently closed documents, peek help, HTML copy and others.

Connection Resiliency Feature In Entity Framework 6 | Visual Studio 2013

,

The new Connection Resiliency feature in EF6 enables you to register an execution strategy to handle – and potentially retry – failed database operations. This is especially useful when deploying to cloud environments where dropped connections become more common as you traverse load balancers and distributed networks.
EF6 includes a built-in execution strategy for SQL Azure that knows about retryable exception types and has some sensible – but overridable – defaults for the number of retries and time between retries when errors occur. Registering it is simple using the new Code-Based Configuration support:
clip_image002[4]

Async and Task Support For Entity Framework 6 In Visual Studio 2013

,

EF6’s new Async Query and Save support enables you to perform asynchronous data access and take advantage of the Task<T> support introduced in .NET 4.5 within data access scenarios.  This allows you to free up threads that might otherwise by blocked on data access requests, and enable them to be used to process other requests whilst you wait for the database engine to process operations. When the database server responds the thread will be re-queued within your ASP.NET application and execution will continue.  This enables you to easily write significantly more scalable server code.

Here is an example ASP.NET WebAPI action that makes use of the new EF6 async query methods:
image

Interception and Logging For Entity Framework 6 Is Improved In Visual Studio 2013

,

Interception and SQL logging allows you to view – or even change – every command that is sent to the database by Entity Framework. This includes a simple, human readable log – which is great for debugging – as well as some lower level building blocks that give you access to the command and results. Here is an example of wiring up the simple log to Debug in the constructor of an MVC controller:
image

Custom Code-First Conventions In Entity Framework 6 Improved In Visual Studio 2013

,

The new Custom Code-First Conventions enable bulk configuration of a Code First model – reducing the amount of code you need to write and maintain. Conventions are great when your domain classes don’t match the Code First conventions. For example, the following convention configures all properties that are called ‘Key’ to be the primary key of the entity they belong to. This is different than the default Code First convention that expects Id or <type name>Id.
image

Introducing ASP.NET MVC 5 In Visual Studio 2013

,

The ASP.NET MVC project templates integrate seamlessly with the new One ASP.NET experience and enable you to integrate all of the above ASP.NET Web API, SignalR and Identity improvements. You can also customize your MVC project and configure authentication using the One ASP.NET project creation wizard. The MVC templates have also been updated to use ASP.NET Identity and Bootstrap as well. 
This release of ASP.NET MVC also supports several nice new MVC-specific features including:
  • Authentication filters: These filters allow you to specify authentication logic per-action, per-controller or globally for all controllers.
  • Attribute Routing: Attribute Routing allows you to define your routes on actions or controllers.

ASP.NET Identity In Visual Studio 2013

,

ASP.NET Identity is a new membership system for ASP.NET applications that is getting introduced with Visual Studio 2013.
ASP.NET Identity makes it easy to integrate user-specific profile data with application data. ASP.NET Identity also allows you to choose the persistence model for user profiles in your application. You can store the data in a SQL Server database or another data store, including NoSQL data stores such as Windows Azure Storage Tables. ASP.NET Identity also supports Claims-based authentication, where the user’s identity is represented as a set of claims from a trusted issuer.
Users can login by creating an account on the website using username and password, or they can login using social identity providers (such as Microsoft Account, Twitter, Facebook, Google) or using organizational accounts through Windows Azure Active Directory or Active Directory Federation Services (ADFS).

ASP.NET Scaffolding In Visual Studio 2013

,

ASP.NET Scaffolding is a new code generation framework for ASP.NET Web applications. It makes it easy to add boilerplate code to your project that interacts with a data model. In previous versions of Visual Studio, scaffolding was limited to ASP.NET MVC projects. With Visual Studio 2013, you can now use scaffolding for any ASP.NET project, including Web Forms.
When using scaffolding, Visual Studio 2013 ensure that all required dependencies are automatically installed for you in the project. For example, if you start with an ASP.NET Web Forms project and then use scaffolding to add a Web API Controller, the required NuGet packages and references to enable Web API are added to your project automatically.  To do this, just choose the Add->New Scaffold Item context menu:
image
Support for scaffolding async controllers uses the new async features from Entity Framework 6.

New Features Of ASP.NET and Entity Framework In Visual Studio 2013

, , ,
Below are details on a few of the great ASP.NET, Web Development, and Entity Framework improvements you can take advantage of with this release.  Please visithttp://www.asp.net/vnext for additional release notes, documentation, and tutorials.

One ASP.NET

With the release of Visual Studio 2013, we have taken a step towards unifying the experience of using the different ASP.NET sub-frameworks (Web Forms, MVC, Web API, SignalR, etc), and you can now easily mix and match the different ASP.NET technologies you want to use within a single application.
When you do a File-New Project with VS 2013 you’ll now see a single ASP.NET Project option:
image
Selecting this project will bring up an additional dialog that allows you to start with a base project template, and then optionally add/remove the technologies you want to use in it. 
For example, you could start with a Web Forms template and add Web API or Web Forms support for it, or create a MVC project and also enable Web Forms pages within it:
image
This makes it easy for you to use any ASP.NET technology you want within your apps, and take advantage of any feature across the entire ASP.NET technology span.
Richer Authentication Support
The new “One ASP.NET” project dialog also includes a new Change Authentication button that, when pushed, enables you to easily change the authentication approach used by your applications – and makes it much easier to build secure applications that enable SSO from a variety of identity providers. 
For example, when you start with the ASP.NET Web Forms or MVC templates you can easily add any of the following authentication options to the application:
  • No Authentication
  • Individual User Accounts (Single Sign-On support with FaceBook, Twitter, Google, and Microsoft ID – or Forms Auth with ASP.NET Membership)
  • Organizational Accounts (Single Sign-On support with Windows Azure Active Directory )
  • Windows Authentication (Active Directory in an intranet application)
The Windows Azure Active Directory support is particularly cool.  Last month we updated Windows Azure Active Directory so that developers can now easily create any number of Directories using it (for free and deployed within seconds).  It now takes only a few moments to enable single-sign-on support within your ASP.NET applications against these Windows Azure Active Directories.  Simply choose the “Organizational Accounts” radio button within the Change Authentication dialog and enter the name of your Windows Azure Active Directory to do this:
image
This will automatically configure your ASP.NET application to use Windows Azure Active Directory and register the application with it.  Now when you run the app your users can easily and securely sign-in using their Active Directory credentials within it – regardless of where the application is hosted on the Internet.
For more information about the new process for creating web projects, see Creating ASP.NET Web Projects in Visual Studio 2013.

Responsive Project Templates with Bootstrap

The new default project templates for ASP.NET Web Forms, MVC, Web API and SPA are built using Bootstrap. Bootstrap is an open source CSS framework that helps you build responsive websites which look great on different form factors such as mobile phones, tables and desktops. For example in a browser window the home page created by the MVC template looks like the following:
image
When you resize the browser to a narrow window to see how it would like on a phone, you can notice how the contents gracefully wrap around and the horizontal top menu turns into an icon:
image
When you click the menu-icon above it expands into a vertical menu – which enables a good navigation experience for small screen real-estate devices:
image
We think Bootstrap will enable developers to build web applications that work even better on phones, tablets and other mobile devices – and enable you to easily build applications that can leverage the rich ecosystem of Bootstrap CSS templates already out there.  You can learn more about Bootstrap here.

Visual Studio Web Tooling Improvements

Visual Studio 2013 includes a new, much richer, HTML editor for Razor files and HTML files in web applications. The new HTML editor provides a single unified schema based on HTML5. It has automatic brace completion, jQuery UI and AngularJS attribute IntelliSense, attribute IntelliSense Grouping, and other great improvements.
For example, typing “ng-“ on an HTML element will show the intellisense for AngularJS:
image
This support for AngularJS, Knockout.js, Handlebars and other SPA technologies in this release of ASP.NET and VS 2013 makes it even easier to build rich client web applications:
image
The screen shot below demonstrates how the HTML editor can also now inspect your page at design-time to determine all of the CSS classes that are available. In this case, the auto-completion list contains classes from Bootstrap’s CSS file. No more guessing at which Bootstrap element names you need to use:
image
Visual Studio 2013 also comes with built-in support for both CoffeeScript and LESS editing support. The LESS editor comes with all the cool features from the CSS editor and has specific Intellisense for variables and mixins across all the LESS documents in the @import chain.

Browser Link – SignalR channel between browser and Visual Studio

The new Browser Link feature in VS 2013 lets you run your app within multiple browsers on your dev machine, connect them to Visual Studio, and simultaneously refresh all of them just by clicking a button in the toolbar. You can connect multiple browsers (including IE, FireFox, Chrome) to your development site, including mobile emulators, and click refresh to refresh all the browsers all at the same time.  This makes it much easier to easily develop/test against multiple browsers in parallel.
image
Browser Link also exposes an API to enable developers to write Browser Link extensions.  By enabling developers to take advantage of the Browser Link API, it becomes possible to create very advanced scenarios that crosses boundaries between Visual Studio and any browser that’s connected to it. Web Essentials takes advantage of the API to create an integrated experience between Visual Studio and the browser’s developer toolsremote controlling mobile emulators and a lot more.
You will see us take advantage of this support even more to enable really cool scenarios going forward.

ASP.NET Scaffolding

ASP.NET Scaffolding is a new code generation framework for ASP.NET Web applications. It makes it easy to add boilerplate code to your project that interacts with a data model. In previous versions of Visual Studio, scaffolding was limited to ASP.NET MVC projects. With Visual Studio 2013, you can now use scaffolding for any ASP.NET project, including Web Forms.
When using scaffolding, we ensure that all required dependencies are automatically installed for you in the project. For example, if you start with an ASP.NET Web Forms project and then use scaffolding to add a Web API Controller, the required NuGet packages and references to enable Web API are added to your project automatically.  To do this, just choose the Add->New Scaffold Item context menu:
image
Support for scaffolding async controllers uses the new async features from Entity Framework 6.

ASP.NET Identity

ASP.NET Identity is a new membership system for ASP.NET applications that we are introducing with this release.
ASP.NET Identity makes it easy to integrate user-specific profile data with application data. ASP.NET Identity also allows you to choose the persistence model for user profiles in your application. You can store the data in a SQL Server database or another data store, including NoSQL data stores such as Windows Azure Storage Tables. ASP.NET Identity also supports Claims-based authentication, where the user’s identity is represented as a set of claims from a trusted issuer.
Users can login by creating an account on the website using username and password, or they can login using social identity providers (such as Microsoft Account, Twitter, Facebook, Google) or using organizational accounts through Windows Azure Active Directory or Active Directory Federation Services (ADFS).
To learn more about how to use ASP.NET Identity visit http://www.asp.net/aspnet/overview/authentication-and-identity

ASP.NET Web API 2

ASP.NET Web API 2 has a bunch of great improvements including:

Attribute routing

ASP.NET Web API now supports attribute routing, thanks to a contribution by Tim McCall, the author of http://attributerouting.net. With attribute routing you can specify your Web API routes by annotating your actions and controllers like this:
image

OAuth 2.0 support

The Web API and Single Page Application project templates now support authorization using OAuth 2.0. OAuth 2.0 is a framework for authorizing client access to protected resources. It works for a variety of clients including browsers and mobile devices.

OData Improvements

ASP.NET Web API also now provides support for OData endpoints and enables support for both ATOM and JSON-light formats. With OData you get support for rich query semantics, paging, $metadata, CRUD operations, and custom actions over any data source. Below are some of the specific enhancements in ASP.NET Web API 2 OData.
  • Support for $select, $expand, $batch, and $value
  • Improved extensibility
  • Type-less support
  • Reuse an existing model

OWIN Integration

ASP.NET Web API now fully supports OWIN and can be run on any OWIN capable host. With OWIN integration, you can self-host Web API in your own process alongside other OWIN middleware, such as SignalR.
For more information, see Use OWIN to Self-Host ASP.NET Web API.

More Web API Improvements

In addition to the features above there have been a host of other features in ASP.NET Web API, including
  • CORS support
  • Authentication Filters
  • Filter Overrides
  • Improved Unit Testability
  • Portable ASP.NET Web API Client
To learn more go to http://www.asp.net/web-api/

ASP.NET SignalR 2

ASP.NET SignalR is library for ASP.NET developers that dramatically simplifies the process of adding real-time web functionality to your applications.
Real-time web functionality is the ability to have server-side code push content to connected clients instantly as it becomes available. SignalR 2.0 introduces a ton of great improvements. We’ve added support for Cross-Origin Resource Sharing (CORS) to SignalR 2.0. iOS and Android support for SignalR have also been added using the MonoTouch and MonoDroid components from the Xamarin library (for more information on how to use these additions, see the article Using Xamarin Components from the SignalR wiki).
We’ve also added support for the Portable .NET Client in SignalR 2.0 and created a new self-hosting package. This change makes the setup process for SignalR much more consistent between web-hosted and self-hosted SignalR applications.
To learn more go to http://www.asp.net/signalr.

ASP.NET MVC 5

The ASP.NET MVC project templates integrate seamlessly with the new One ASP.NET experience and enable you to integrate all of the above ASP.NET Web API, SignalR and Identity improvements. You can also customize your MVC project and configure authentication using the One ASP.NET project creation wizard. The MVC templates have also been updated to use ASP.NET Identity and Bootstrap as well. An introductory tutorial to ASP.NET MVC 5 can be found at Getting Started with ASP.NET MVC 5.
This release of ASP.NET MVC also supports several nice new MVC-specific features including:
  • Authentication filters: These filters allow you to specify authentication logic per-action, per-controller or globally for all controllers.
  • Attribute Routing: Attribute Routing allows you to define your routes on actions or controllers.
To learn more go to http://www.asp.net/mvc

Entity Framework 6 Improvements

Visual Studio 2013 ships with Entity Framework 6, which bring a lot of great new features to the data access space:

Async and Task<T> Support

EF6’s new Async Query and Save support enables you to perform asynchronous data access and take advantage of the Task<T> support introduced in .NET 4.5 within data access scenarios.  This allows you to free up threads that might otherwise by blocked on data access requests, and enable them to be used to process other requests whilst you wait for the database engine to process operations. When the database server responds the thread will be re-queued within your ASP.NET application and execution will continue.  This enables you to easily write significantly more scalable server code.
Here is an example ASP.NET WebAPI action that makes use of the new EF6 async query methods:
image

Interception and Logging

Interception and SQL logging allows you to view – or even change – every command that is sent to the database by Entity Framework. This includes a simple, human readable log – which is great for debugging – as well as some lower level building blocks that give you access to the command and results. Here is an example of wiring up the simple log to Debug in the constructor of an MVC controller:
image

Custom Code-First Conventions

The new Custom Code-First Conventions enable bulk configuration of a Code First model – reducing the amount of code you need to write and maintain. Conventions are great when your domain classes don’t match the Code First conventions. For example, the following convention configures all properties that are called ‘Key’ to be the primary key of the entity they belong to. This is different than the default Code First convention that expects Id or <type name>Id.
image

Connection Resiliency

The new Connection Resiliency feature in EF6 enables you to register an execution strategy to handle – and potentially retry – failed database operations. This is especially useful when deploying to cloud environments where dropped connections become more common as you traverse load balancers and distributed networks.
EF6 includes a built-in execution strategy for SQL Azure that knows about retryable exception types and has some sensible – but overridable – defaults for the number of retries and time between retries when errors occur. Registering it is simple using the new Code-Based Configuration support:
clip_image002[4]
These are just some of the new features in EF6. You can visit the release notes section of the Entity Framework site for a complete list of new features.

Microsoft OWIN Components

Open Web Interface for .NET (OWIN) defines an open abstraction between .NET web servers and web applications, and the ASP.NET “Katana” project brings this abstraction to ASP.NET.
OWIN decouples the web application from the server, making web applications host-agnostic. For example, you can host an OWIN-based web application in IIS or self-host it in a custom process.
For more information about OWIN and Katana, see What's new in OWIN and Katana.

Summary

Today’s Visual Studio 2013, ASP.NET and Entity Framework release delivers some fantastic new features that streamline your web development lifecycle. These feature span from server framework to data access to tooling to client-side HTML development.  They also integrate some great open-source technology and contributions from our developer community.

This post was originally Appeared on Scott Gu's Blog

Recommended C# Data Type for SQL Server Image Data Type - C#

, , ,

According to a Microsoft document in managing ntext, text, and image Data, avoid using this feature in new development work. Use varchar(max), nvarchar(max), and varbinary(max) data types instead

byte[] is the recommended C# data type equivalent to image data type of SQL Server.

For example, the below SQL statement shows ProductImages table with an Image type column

CREATE TABLE [ProductImages]
(
[ProductImageID] [int] IDENTITY(1,1) NOT NULL,
[ProductImage] [image] NOT NULL
 CONSTRAINT [PK_ProductImages] PRIMARY KEY CLUSTERED
 (
   [ProductImageID] ASC
 ) 
)

This can be defined in a ProductImages C# class. Note that the SQL Server Image type is mapped with C# byte[] type

public class ProductImages
{
    private int productImageID;

    public int ProductImageID
    {
        get { return productImageID; }
        set { productImageID = value; }
    }

    private byte[] productImage;

    public byte[] ProductImage
    {
        get { return productImage; }
        set { productImage = value; }
    }

}

Create NewApp in Facebook and Connect the App to ASP.NET MVC Project - ASP.NET MVC

, ,

Facebook ASP.NET MVC Template provides boilerplate code to connect your application to Facebook and retrieve Facebook properties such as Likes, photos, email and friends profile details. However, in order to get your application connect and interact with Facebook, we need to configure some settings from an application that you created in Facebook copy to your ASP.NET MVC project.

  1. In your browser, navigate to https://developers.facebook.com/apps and log in by entering your Facebook credentials.
  2. If you aren’t already registered as a Facebook developer, click Register as a Developer and follow the directions to register.
  3. Click Create New App.(Figure 1)
  4. Enter an App Name and App Namespace, and then click Continue.(Figure 2)
  5. On the Basic Settings page for the app, set the Sandbox Mode to Enabled. This ensures that you have exclusive access to the app until it's ready to be made available to everyone.(Figure 3)
  6. In Visual Studio, open the application Web.config file that is located in the root folder of your project.
  7. Copy and paste the AppId, App Secret, and App Namespace values into the corresponding key elements in the appSettings collection in the Web.config file.(Figure 4)
  8. In Solution Explorer, right-click the project and click Properties, and then click the Web tab.
  9. Copy the Project URL from the Web tab and paste it into the Canvas URL field in the Facebook Basic Settings page.(Figure 5)
  10. Change Canvas Width to Fluid.
  11. Click Save Changes.(Figure 6)
  12. Press CTRL+F5 to run the application.

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Adding a Class Attribute via Html.BeginForm - ASP.NET MVC

,

We can specify the css class attribute in an HTML helper method BeginForm as below in ASP.NET MVC Application

Html.BeginForm("MyActionName", "MyControllerName", FormMethod.Post, new { @class = "myclass"})

Rendering Textarea Using @Html.EditorFor | ASP.NET MVC

,

The default view generated will render an input control of type text for a string field.

@Html.EditorFor(model => model.Text)

However, if you want to have a textarea for the string field to facilitate the user to provide multiline text, we need to use [DataType] attribute on your view model

public class MyViewModel
{
    [DataType(DataType.MultilineText)]
    public string Text { get; set; }
}

Don't forget to import System.ComponentModel.DataAnnotations as below

using System.ComponentModel.DataAnnotations;

Now, your view will render a textarea for the string field.

ASP.NET MVC Facebook Application | ASP.NET MVC

, ,

Visual Studio 2012 recent update released (VS2012.2) contains an enhancement to ASP.NET MVC that introduced new Facebook Application template. This tutorial will teach you to build a Facebook canvas application using Facebook Applications Template in Visual Studio 2012

Facebook Canvas applications using ASP.NET MVC Facebook Application template

Facebook Application template includes necessary library to build Facebook canvas application. Facebook Application template will ease of writing code for authentication, permissions, and accessing Facebook data. The Facebook Application template also has an extensibility model to build your own storage providers.

Prerequisites to create a Facebook Canvas Application in ASP.NET MVC
  • Visual Studio 2012 or Visual Studio Express 2012
  • ASP.NET and Web Tools 2012.2 update for Visual Studio 2012
Steps to Create Facebook Canvas applications using ASP.NET MVC Facebook Application template
  1. Run Visual Studio 2012 or Visual Studio Express for Web 2012.
  2. From the File menu, click New Project.
  3. In the New Project dialog box, expand C# and then click Web under Templates.
  4. Click ASP.NET MVC 4 Web Application.
  5. Leave the .NET Framework version set to .NET 4.5 for developing Facebook template requires.
  6. Enter HelloWorldFacebookApp for the project name, and then click OK.(Figure 1)
  7. In the New ASP.NET MVC 4 Project dialog box, click Facebook Application, and then click OK.(Figure 2)
Figure 1




Figure 2

Microsoft ASP.NET Web Optimization Framework | ASP.NET

,

ASP.NET Web Optimization Framework facilitates a new way to bundle css and js files.

In order to utilize the features of ASP.NET Web Optimization Framework in our project, we need to do the following steps.

First, install the package of ASP.NET Web Optimization Framework from nuget by running the below command

Install-Package Microsoft.AspNet.Web.Optimization

Create and configure bundle(s) in App_Start\BundleConfig.cs as below

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles) {
        bundles.Add(new ScriptBundle("~/Scripts/jquery").Include(
            "~/Scripts/Lib/jquery/jquery-{version}.js",
            "~/Scripts/Lib/jquery/jquery.*",
            "~/Scripts/Lib/jquery/jquery-ui-{version}.js")
        );

        bundles.Add(new ScriptBundle("~/Scripts/knockout").Include(
             "~/Scripts/Lib/knockout/knockout-{version}.js",
             "~/Scripts/Lib/knockout/knockout-deferred-updates.js")
        );
    }
}

Call the RegisterBundles() function from Application_Start() in your global.asax.cs as below

using System.Web.Optimization;

protected void Application_Start() {
     ...
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     ...
}

Include the Optimization namespace and render the bundle(s) in your view.cshtml as below

@using System.Web.Optimization

@Scripts.Render("~/Scripts/jquery")
@Styles.Render("~/Content/themes/base/css", "~/Content/css")

Constraints on Type Parameters In Generics | C#

,

Generics are a template/blueprint of a Classes/Methods/Types were the actual type is defined at Runtime. Parameter types must be defined at the time of creating the instances. A Generic Class can accept any type of parameter. But sometimes it is necessary to implement a generic Class that can be instantiated with only specific types.

Constraints on generics restricts the allowable types while declaring the generic type. A compile-time error will be thrown if you attempt to instantiate a class with a type that is not allowed by a constraint.

Let's walk through with the below class, Circle

public class Circle
{
}
Implementing Generic Constraints on Type Paramenters in C#

The Circle class is rewritten by implementing a generic constraints so that Circle class can be instantiated to a Value Type only.

public class Circle
   where T1 : struct
{
   ...
}

Below code shows the Circle class rewritten using generic constraints in such a way that it can be instantiated to a Reference Type only.

public class Circle
   where T1 : class
{
   ...
}

Below code shows the Circle class rewritten using generic constraints in such a way that it can be instantiated with the type argument that must have a public parameterless constructor.

public class Circle
   where T1 : new()
{
   ...
}

Below code shows the Circle class rewritten using generic constraints in such a way that it can be instantiated with the type argument that must be or derive from the specified base class, MyBaseClass here.

public class Circle
   where T1 : MyBaseClass
{
   ...
}

Below code shows the Circle class rewritten using generic constraints in such a way that it can be instantiated with the type argument that must or implement the specified interface, IMyInterface here.

public class Circle
   where T1 : IMyInterface
{
   ...
}

Below code shows the Circle class rewritten using generic constraints in such a way that it can be instantiated with the type argument supplied for T must be or derive from the argument supplied for U.

public class Circle
   where T : U
{
   ...
}