What is the MVC Pattern (Model View Controller Pattern)?

The MVC Pattern (Model View Controller Pattern) is based on the concept of designing an application by dividing its functionalities into 3 layers. Its like a triad of components. The Model component contains the business logic, or the other set of re-usable classes like classes pertaining to data access, custom control classes, application configuration classes etc. The Controller component interacts with the Model whenever required. The control contains events and methods inside it, which are raised from the UI which is the View component.

Consider an ASP.NET web application. Here, all aspx, ascx, master pages represent the View. The code behind files (like aspx.cs, master.cs, ascx.cs) represent the Controller.

The classes contained in the App_Code folder, or rather any other class project being referenced from this application represent the Model component.

Advantages:

  • Business logic can be easily modified, without affecting or any need to make changes in the UI.
  • Any cosmetic change in the UI does not affect any other component.

 

#mvc

When do we use a DOM parser and when do we use a SAX parser?

DOM: Document Object Modal
SAX: Simple API for XML

The answer to above question is,

the DOM Approach is useful for small documents in which the program needs to process a large portion of the document whereas the SAX approach is useful for large documents in which the program only needs to process a small portion of the document.

#dom, #sax

What is Serialization?

Serialization of object is very old technique and it does not depend on .NET.

When an object is serialized, the data stored in the object (including reference to other objects) is converted into the stream of bytes that can be more easily stored into the database or other file system.

This serialized data can be utilized in future to rebuild the object and this process is known as deserialization.

Before .NET it was possible to serialized/deserialized the object but it required more manual coding.

Since, object is base data type in .NET, serialization/deserialization functionality is built in to the Framework.

#serialization

What is the limit on the number of tables in a query in SQL Server?

With SQL 6.5 and earlier the limit is 16 – regardless of which “version” of SQL you are running – i.e. Enterprise Edition allows no more than standard. With SQL 7.0 the limit is 256. These figures are hard-coded into the SQL kernel and are arbitrarily chosen by the Microsoft developers – but with good reason. The more tables there are, the longer it takes to optimize a query properly. There has to be a trade-off between the speed of running a query and the speed of optimizing it.

It *is* possible to up the limit of 16 in SQL 6.5 by setting trace flag -T105. This is an undocumented and unsupported trace flag, so Microsoft may not support you with any problems on a system that is running this. However, it was allegedly put into the product to allow some of the more complex Peoplesoft queries to run, and so it must have had some testing/QA done on it. It ups the limit to 32.

Normally, if a query needs more than 16 tables then you have a very bad query and/or database design. The best practice would be to break the query down into smaller parts and use temporary tables to hold interim result sets. This will also make the query more understandable and may even speed it up as the optimizer has more of a chance to choose correct access plans and indices.

Finally the table limit only applies to a single query, so you could always use a UNION statement to join together the results of two separate queries.

#max-number-of-tables, #table-limit-in-sql

How can I tell if a column for a table already exists?

Below are the two ways in SQL server to identify whether column in a particular table Exists or Not.

Create Table Employee (ID int, Name varchar(100))
GO

--Way 1

IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Employee' AND COLUMN_NAME = 'Name')
BEGIN
		PRINT 'EXISTS'
END
ELSE
BEGIN
		PRINT 'DOESN''T EXISTS'
END

IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Employee' AND COLUMN_NAME = 'Adress')
BEGIN
		PRINT 'EXISTS'
END
ELSE
BEGIN
		PRINT 'DOESN''T EXISTS'
END

--Way 2
if columnproperty (object_id('Employee'), 'Name', 'AllowsNull') IS NOT NULL
BEGIN
		PRINT 'EXISTS'
END
ELSE
BEGIN
		PRINT 'DOESN''T EXISTS'
END

if columnproperty (object_id('Employee'), 'Address', 'AllowsNull') IS NOT NULL
BEGIN
		PRINT 'EXISTS'
END
ELSE
BEGIN
		PRINT 'DOESN''T EXISTS'
END

#if-exists-for-column