User Not Logged In More Than 15 Days

Sunday 18 May 2014


List of User not logged in more than 15 days Report with HTML Look when send from SQL Server
·         You can create a stored procedure shown below with styling.


·         When you send it through SQL Scheduler ,it will look as below:-

Read more ...

MVC Interview Questions Set 2

Sunday 18 May 2014

1. What is main focus of ASP.NET MVC 4?
Ans. The main focus of ASP.NET MVC 4 is making it easier to develop mobile web applications. Other than mobile web applications it’s focus is also on better HTML5 support and making ASP.NET MVC web application cloud ready. Using new features of ASP.NET MVC 4 you can develop web applications that can work well across different mobile devices and desktop web browsers.

2. What is ASP.NET Web API?
Ans. ASP.NET Web API is a framework for building and consuming HTTP Services. It supports wide range of clients including browsers and mobile devices. It is a great platform for developing RESTful services since it talks HTTP.

3. You can also develop RESTful services using WCF, then why this new framework Web API?
Ans. Yes we can still develop RESTful services with WCF, but there are two things that prompt users to use ASP.NET Web API over WCF for development of RESTful services. First one is ASP.NET Web API is included in ASP.NET MVC which obviously increases TDD approach in the development of RESTful services. Second one is for developing RESTful services in WCF you still needs lot of configurations, URI templates, contracts and endpoints which developing RESTful services using ASP.NET Web API is simple.

4. What are the enhancements done in default project template of ASP.NET MVC 4?
Ans. The enhanced default project template is modern-looking. Along with cosmetic enhancements, it also employs adaptive rendering to look nice in both desktop and mobile browsers without need of any kind of additional customization.

5. Why separate mobile project template while you can render your web application in mobile without additional customization?
Ans. The mobile project template touch-optimized UI using jQuery.Mobile.MVC NuGet Package for smart phones and tablets.

6. What is Display Modes?
Ans. Display Modes is new feature provided in ASP.NET MVC 4. It lets an application select views depending on the browser which is making request. For example, if a desktop browser requests home page of an application it will return Views\Home\Index.cshtml view and if a mobile browser requests home page it will return Views\Home\Index.mobile.cshtml view.

8. What is Bundling and Minification feature provided in ASP.NET MVC 4?
Ans. It reduces number of HTTP requests that a web page needs to make. Bundling and Minification combines individual files into single, bundled file for scripts and CSS and then reduce the overall size by minifying the contents of the bundle.

9. While developing application using ASP.NET MVC 4, I want to provide authentication using popular sites like Facebook or twitter into my web application, is it possible in ASP.NET MVC 4?
Ans. Yes, using DotNetOpenAuth library we can provide authentication using OAuth or OpenID providers. In ASP.NET MVC 4 Internet project template includes this library.

10. What’s the difference between Empty MVC Project template in ASP.NET MVC 3 and ASP.NET MVC 4?
Ans. The ASP.NET MVC 4 Empty project template is really empty. It does not contain any css and js files as compared to previous Empty project template, which contains all these files.

11. What are the main features of ASP.NET MVC used by ASP.NET Web API?
Ans. Routing: ASP.NET Web API uses same convention for configuration mapping that ASP.NET MVC provides. Model Binding and Validation: ASP.NET Web API uses same model binding functionality, but tailored to HTTP specific context related operations only. Filters: The ASP.NET Web API uses lots of filters built-in MVC. Unit Testing: Now it’s based on MVC, truly unit testable.

12. If I want to create resource oriented services that can use full features of HTTP like cache control for browsers, use URI templates to include Task URIs in your responses, versioning and concurrancy using ETags, pass various content types such as images, documents, HTML pages etc. then which is preferred for development of services, WCF or Web API?
Ans. In such scenario Web API would be preferred choice. Using Web APIs we can develop services which utilizes full features of HTTP.

13. Suppose I want to develop services which supports special scenarios like one way messaging, duplex communication, message queues, ete then which is the best way to develop services, WCF or Web API?
Ans. In this scenario WCF suits the requirement. WCF provides all kine of messaging facility.

14. Now, if I want to create services which are exposed over various transport channels like TCP, Named Pipe or even UDP. I also want the support of HTTP transport channel when other transport channels are unavailable then which is the preferred way, WCF or Web API and why?
Ans. For such scenario WCF is preferred way for development of services because WCF support almost all kind of transport mechanism and we need to expose SOAP-based and WebHTTP-based bindings.

15. What is the difference between asynchronous controller implementation between ASP.NET MVC 3 and ASP.NET MVC 4? Can you explain in detail?
Ans. There is large difference between the working and implementation mechanism between ASP.NET MVC 3 and ASP.NET MVC 4.

In ASP.NET MVC 3, to implement asynchronous controller/methods you need to derive controller from AsyncController rather than from plain Controller class. You need to create two action methods rather than one. Fist with suffix “Async” keyword and second with “Completed” suffix. The method which initiated asynchronous process must end with “Async” and the method which is invoked when the asynchronous process finishes must end with “Completed”. Following is example showing the same.

//Synchronous Implementation

public class SynchronousTestController : Controller

{

    public ActionResult Index()

    {

        method1();

        method2();

        return View();

    }

}

//Asynchronous Implementation in ASP.NET MVC 3

public class AsynchronousTestController : AsyncController

{

    public void IndexAsync()

    {

        method1();

        method2();

    }

    public ActionResult IndexCompleted()

    {

        return View("Index");

    }

}

The ASP.NET MVC 4 Controller class in combination .NET 4.5 enables you to write asynchronous action methods that return an object of type Task. The .NET Framework 4 introduced an asynchronous programming concept referred to as a Task and ASP.NET MVC 4 supports Task. The .NET Framework 4.5 builds on this asynchronous support with the await and async keywords that make working with Task objects much less complex than previous asynchronous approaches. The await keyword is syntactical shorthand for indicating that a piece of code should asynchronously wait on some other piece of code. The async keyword represents a hint that you can use to mark methods as task-based asynchronous methods. To implement asynchronous action method in ASP.NET MVC 4 we do no need to derive our controller class from AsyncController, async and await in cooperation with Task will do the magic. To mark the action method asynchronous use async in method signature. To wait for the other method to finish use await and to call multiple parallel methods use Task. The asynchronous method will return Task instead of plain ActionResult.

public class AsyncronousTestController : Controller

{

    public async Task<ActionResult> IndexAsync()

    {

        //if single method

        //await method();

        //if multiple methods

        await Task.WhenAll(method1(), method2());

        return View("Index");

    }

}

Here the await keyword does not block the thread execution until the task is complete. It signs up the rest of the method as a callback on the task, and immediately returns. When the awaited task eventually completes, it will invoke that callback and thus resume the execution of the method right where it left off.

16. Can you tell us some guidelines for when to use synchronous and when to use asynchronous approach?
Ans. In following situations synchronous approach is more suited.

    The operations are simple or short-running.
    Simplicity is more important than efficiency.
    The operations are primarily CPU operations instead of operations that involve extensive disk or network overhead. Using asynchronous action methods on CPU-bound operations provides no benefits and results in more overhead.

For asynchronous approach some of the guidelines are

    You’re calling services that can be consumed through asynchronous methods, and you’re using .NET 4.5 or higher.
    The operations are network-bound or I/O-bound instead of CPU-bound.
    Parallelism is more important than simplicity of code.
    You want to provide a mechanism that lets users cancel a long-running request.
    When the benefit of switching threads out weights the cost of the context switch. In general, you should make a method asynchronous if the synchronous method waits on the ASP.NET request thread while doing no work. By making the call asynchronous, the ASP.NET request thread is not stalled doing no work while it waits for the web service request to complete.
    Testing shows that the blocking operations are a bottleneck in site performance and that IIS can service more requests by using asynchronous methods for these blocking calls.

17. Which latest version of Entity Framework is included by ASP.NET MVC 4? What is the advantage of it?
Ans. ASP.NET MVC 4 is included Entity Framework 5. The main advantage of Entity Framework 5 is it’s new feature called database migration. It enables you to easily evolve your database schema using a code-focused migration while preserving the data in the database.


18. What are the provisions for real time communication in ASP.NET MVC 4?
Ans. ASP.NET MVC 4 supports WebSockets along with the new open source framework SignalR which allows to set up real time multi-user communication through open TCP sockets.

19. What is the enhancement provided related to custom controller in ASP.NET MVC 4?
Ans. In ASP.NET MVC 4 you can place custom controller to custom locations. In ASP.NET MVC 3 you can only place custom controllers inside the Controllers folder.


20 Difference Between Asp.Net Web Forms and Asp.Net MVC?

Ans



Asp.Net Web Forms
Asp.Net MVC
Asp.Net Web Form follow a traditional event driven development model.
Asp.Net MVC is a lightweight and follow MVC (Model, View, Controller) pattern based development model.
Asp.Net Web Form has server controls.
Asp.Net MVC has html helpers.
Asp.Net Web Form has state management (like as view state, session) techniques.
Asp.Net MVC has no automatic state management techniques.
Asp.Net Web Form has file-based URLs means file name exist in the URLs must have its physically existence.

Asp.Net MVC has route-based URLs means URLs are divided into controllers and actions and moreover it is based on controller not on physical file.
Asp.Net Web Form follows Web Forms Syntax.
Asp.Net MVC follow customizable syntax (Razor as default)
In Asp.Net Web Form, Web Forms(ASPX) i.e. views are tightly coupled to Code behind(ASPX.CS) i.e. logic.
In Asp.Net MVC, Views and logic are kept separately.

Asp.Net Web Form has Master Pages for consistent look and feels.
Asp.Net MVC has Layouts for consistent look and feels.
Asp.Net Web Form has User Controls for code re-usability.
Asp.Net MVC has Partial Views for code re-usability.
Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access.

Asp.Net MVC is lightweight, provide full control over markup and support many features that allow fast & agile development. Hence it is best for developing interactive web application with latest web standards.
Asp.Net Web Form is not Open Source.
Asp.Net Web MVC is an Open Source.


Read more ...

Entity Framework Question

Sunday 18 May 2014

What is Entity Framework?

Entity Framework is an additional layer between application and database that enables the developers to program against the conceptual application model instead of programming directly against the relational storage schema.

Will there be any issues adding a table without primary keys to a data model?

Every entity must have a key, even in the case where the entity maps to a view. When you use the Entity Designer to create or update a model, the classes that are generated inherit from EntityObject, which requires EntityKey. So, we have to have a primary key in the table to add it to the data model.

How do you truncate a table using entity data model?

Unfortunately Entity Framework doesn’t include anything straight forward to handle this. But we can still call a T-SQL statement using entity framework that will still minimizes the developers work. We can call ExecuteStoreCommand() methond on ObjectContext as shown below.

using (var context = new MyTestDbEntities())

{

    context.ExecuteStoreCommand("TRUNCATE table Dummy");

}

How do you query in entity model when the result has a join from from different database other than the entity model? E.g.: SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1

As the entity model doesn’t support querying from any entity other than the entities defined in Entity Data Model, we have to query aginst the data base using ExecuteStoredQuery of the context.

Following code snippet shows how to query when other databases are joined.

string query = "SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1";

using (var context = new SampleEntities())

{

  ObjectResult<DbDataRecord> records = context.ExecuteStoreQuery<DbDataRecord>(query);

  foreach (DbDataRecord record in records)

  {

    //Do whatever you want

  }

}

What is minimum requirement for Entity Framework applications to run?

The Entity Framework is a component of the .NET Framework so Entity Framework applications can run on any computer on which the .NET Framework starting with version 3.5 SP1 is installed.

What is CSDL?

Conceptual schema definition language (CSDL) is an XML-based language that describes the entities, relationships, and functions that make up a conceptual model of a data-driven application. This conceptual model can be used by the Entity Framework or WCF Data Services.

The metadata that is described with CSDL is used by the Entity Framework to map entities and relationships that are defined in a conceptual model to a data source. More=> http://msdn.microsoft.com/en-us/library/bb399292.aspx

What is SSDL?

Store schema definition language (SSDL) is an XML-based language that describes the storage model of an Entity Framework application.

In an Entity Framework application, storage model metadata is loaded from a .ssdl file (written in SSDL) into an instance of the System.Data.Metadata.Edm.StoreItemCollection and is accessible by using methods in the System.Data.Metadata.Edm.MetadataWorkspace class. The Entity Framework uses storage model metadata to translate queries against the conceptual model to store-specific commands. More=> http://msdn.microsoft.com/en-us/library/bb399559.aspx

What is MSL?

Mapping specification language (MSL) is an XML-based language that describes the mapping between the conceptual model and storage model of an Entity Framework application.

In an Entity Framework application, mapping metadata is loaded from an .msl file (written in MSL) at build time. The Entity Framework uses mapping metadata at runtime to translate queries against the conceptual model to store-specific commands. More=> http://msdn.microsoft.com/en-us/library/bb399202.aspx

What is Entity Data Model?

The Entity Data Model (EDM) is a set of concepts that describe the structure of data, regardless of its stored form. The EDM borrows from the Entity-Relationship Model described by Peter Chen in 1976, but it also builds on the Entity-Relationship Model and extends its traditional uses.

The EDM addresses the challenges that arise from having data stored in many forms. For example, consider a business that stores data in relational databases, text files, XML files, spreadsheets, and reports. This presents significant challenges in data modeling, application design, and data access. When designing a data-oriented application, the challenge is to write efficient and maintainable code without sacrificing efficient data access, storage, and scalability. When data has a relational structure, data access, storage, and scalability are very efficient, but writing efficient and maintainable code becomes more difficult. When data has an object structure, the trade-offs are reversed: Writing efficient and maintainable code comes at the cost of efficient data access, storage, and scalability. Even if the right balance between these trade-offs can be found, new challenges arise when data is moved from one form to another. The Entity Data Model addresses these challenges by describing the structure of data in terms of entities and relationships that are independent of any storage schema. This makes the stored form of data irrelevant to application design and development. And, because entities and relationships describe the structure of data as it is used in an application (not its stored form), they can evolve as an application evolves. More=> http://msdn.microsoft.com/en-us/library/ee382825.aspx

Which are the key concepts of Entity Data Model?

The Entity Data Model (EDM) uses three key concepts to describe the structure of data: entity type, association type, and property. These are the most important concepts in describing the structure of data in any implementation of the EDM.

1. Entity Type: The entity type is the fundamental building block for describing the structure of data with the Entity Data Model. In a conceptual model, entity types are constructed from properties and describe the structure of top-level concepts, such as a customers and orders in a business application.

2. Association Type: An association type (also called an association) is the fundamental building block for describing relationships in the Entity Data Model. In a conceptual model, an association represents a relationship between two entity types (such as Customer and Order).

3. Property: Entity types contain properties that define their structure and characteristics. For example, a Customer entity type may have properties such as CustomerId, Name, and Address. More=> http://msdn.microsoft.com/en-us/library/ee382840.aspx

What is .edmx file and what it contains?

An .edmx file is an XML file that defines a conceptual model, a storage model, and the mapping between these models. An .edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.

How can you tell EF to have a different table or column name than that defined for the class?

By convention, EF defines the table and column names based on your class and property names.

You can use the [Table] and [Column] annotations to tell EF to use different names.
How do you mark a property as required? For example, For a Project, the Name is a required field.

You use the [Required] attribute to mark a property as required.

What is use of EntityDataSource Control?

The ADO.NET EntityDataSource control supports data binding scenarios in Web applications that use the ADO.NET Entity Framework. Like the Entity Framework, the control is available as part of the .NET Framework 3.5, beginning with SP1. Like the other Web server data source controls, the EntityDataSource control manages create, read, update, and delete operations against a data source on behalf of data-bound controls on the same page. The EntityDataSource works with editable grids, forms with user-controlled sorting and filtering, dually bound drop-down list controls, and master-detail pages.

What is Model First Approach?

A new Model First approach was supported in Visual Studio 2010, which was released together with the second Entity Framework version (Entity Framework v4). In Model First approach the development starts from scratch. At first, the conceptual model is created with Entity Data Model Designer, entities and relations are added to the model, but mapping is not created.

After this Generate Database Wizard is used to generate storage (SSDL) and mapping (MSL) parts from the conceptual part of the model and save them to the edmx file. Then the wizard generates DDL script for creating database (tables and foreign keys)

If the model was modified, the Generate Database Wizard should be used again to keep the model and the database consistent. In such case, the generated DDL script contains DROP statements for tables, corresponding to old SSDL from the .edmx file, and CREATE statements for tables, corresponding to new SSDL, generated by the wizard from the conceptual part. In Model First approach developer should not edit storage part or customize mapping, because they will be re-generated each time when Generate Database Wizard is launched.

What is Code First Approach?

Code First allows you to define your model using C# or VB.Net classes, optionally additional configuration can be performed using attributes on your classes and properties or by using a Fluent API. Your model can be used to generate a database schema or to map to an existing database. More=>http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx

What is Entity SQL?

Entity SQL is a SQL-like storage-independent language, designed to query and manipulate rich object graphs of objects based on the Entity Data Model (EDM). More=>http://msdn.microsoft.com/en-us/library/bb399560(v=vs.90).aspx

What is LINQ To Entities?

LINQ to Entities provides Language-Integrated Query (LINQ) support for querying entities.

LINQ to Entities enables developers to write queries against the database using one of the supported .NET Framework programming languages such as Visual Basic or Visual C#.

What is EntityClient? System.Data.EntityClient is a storage-independent ADO.NET data provider that contains classes such as EntityConnection, EntityCommand, and EntityDataReader. Works with Entity SQL and connects to storage specific ADO.NET data providers, such as SqlClient. More=>http://msdn.microsoft.com/en-us/library/bb738561(v=vs.90).aspx

What is Deferred Loading(Lazy Loading)?

When objects are returned by a query, related objects are not loaded at the same time.

Instead they are loaded automatically when the navigation property is accessed. Also known as “lazy loading,”

What is Eager Loading?

The process of loading a specific set of related objects along with the objects that were explicitly requested in the query. More=>http://msdn.microsoft.com/en-us/library/bb896272(v=vs.90).aspx

What is Complex Type?

A .NET Framework class that represents a complex property as defined in the conceptual model. Complex types enable scalar properties to be organized within entities. Complex objects are instances of complex types. More=>http://msdn.microsoft.com/en-us/library/bb738472(v=vs.90).aspx

What is Conceptual Model?

An implementation of the Entity Data Model (EDM), specific to the Entity Framework, which represents an abstract specification for the data structures that define an entity-relationship representation of data in the domain of an application. More=>http://msdn.microsoft.com/en-us/library/bb399183(v=vs.90).aspx

What is use of Entity Container?

Specifies entity sets and association sets that will be implemented in a specified namespace. More=>http://msdn.microsoft.com/en-us/library/bb399557(v=vs.90).aspx

What is Explicit Loading?

When objects are returned by a query, related objects are not loaded at the same time. By default, they are not loaded until explicitly requested using the Load method on a navigation property.



Read more ...

Sharing

Get widget