Wednesday, August 7, 2013

Visual Studio.NET metadata files and the function they serve when integrated with ClearCase

The following is a living list of information about the various metadata files associated with Visual Studio.NET and ClearCase.

Folder Hierarchy
The Visual Studio.NET (VS.NET) and ClearCase metadata exist in a simple hierarchy of folders. The first folder is the Solution folder and is named after the VS.NET Solution. The Solution folder contains one *.SLN file (see below), at least one *.SUO file (see below), and zero or more VS.NET Project folders. Project folders are named after their VS.NET Projects. The contents of the Project folders vary, but they always contain one *.CSPROJ file (see below) per Project folder, and a *.WEBINFO file (see below) if the Project is a web (ASP.NET) project.


SLN (Solution File)
The VS.NET Solution metadata is stored in the *.sln file. The Solution and all the Projects associated with it can be opened within VS.NET by opening the *.sln file. It is a text file and can be edited. It is version controlled.


CSPROJ (Project File)
The metadata file associated with individual projects is *.csproj. Within VS.NET, opening the *.csproj file will open that individual project. It is a text file and can be edited. It is version controlled.


SUO (Solution User Option File)
When ASP.NET Projects (generally termed as web projects) are created and version controlled, using VS.NET and ClearCase, VS.NET stores absolute paths of key artifacts (like Solution, Project, Web) and source code control information in the Solution User Options (.suo) file in addition to other files. A Solution user option file, is a binary file, which is specific to a given user, and is not version controlled.


.VSSSCC 
The .vssscc file is used by Visual Studio .NET to provide the source control integration of your projects.
They store project bindings, exclusion lists, original web names and more.
These files are required to be in the database along with their solution or project file.


WEBINFO (WEBINFO File)
When a web project (ASP.NET) is created, a *.webinfo file is also created in the same location as the *.CSPROJ. This WEBINFO file is also not version controlled by default. It must be manually added to source control if multiple views must be used with the web project. It is a text file and stores the URL pointing to the web projects *.CSPROJ file.


.CCEXCLUDE (ClearCase Exclusion File)
When using the ClearCase and VS .NET Integration, a file with the extension .ccexclude will be created if you choose the option "Exclude from Source Control" for a particular project file from within the Solution Explorer window. This file is simply a reference file that ClearCase uses to identify what files should not be included with specific source controlling operations, builds, etc. This option can be toggled at the preference of the developers by right-clicking a file and selecting ClearCase > "Include in Source Control" (or ClearCase > "Exclude from Source Control"). Note: The ClearCase Exclude from Source Control option should not be confused with the native Visual Studio .NET Exclude from Project option, information about which can be found in the Microsoft documented procedure

SQL OVER and PARTITION BY

OVER

OVER allows you to get aggregate information without using a GROUP BY. In other words, you can retrieve detail rows, and get aggregate data alongside it. For example, this query:
SELECT SUM(Cost) OVER () AS Cost
, OrderNum
FROM Orders
Will return something like this:
Cost  OrderNum
10.00 345
10.00 346
10.00 347
10.00 348
Quick translation:
  • SUM(cost) – get me the sum of the COST column
  • OVER – for the set of rows….
  • () – …that encompasses the entire result set.

OVER(PARTITION BY)

OVER, as used in our previous example, exposes the entire resultset to the aggregation…”Cost” was the sum of all [Cost]  in the resultset.  We can break up that resultset into partitions with the use of PARTITION BY:
SELECT SUM(Cost) OVER (PARTITION BY CustomerNo) AS Cost
, OrderNum
, CustomerNo

FROM Orders
My partition is by CustomerNo – each “window” of a single customer’s orders will be treated separately from each other “window”….I’ll get the sum of cost for Customer 1, and then the sum for Customer 2:
Cost  OrderNum   CustomerNo
 8.00 345        1
 8.00 346        1
 8.00 347        1
 2.00 348        2
The translation here is:
  • SUM(cost) – get me the sum of the COST column
  • OVER – for the set of rows….
  • (PARTITION BY CustomerNo) – …that have the same CustomerNo.

Wednesday, July 31, 2013

NULL plus anything sql

In SQL NULL plus anything equals NULL

Ex:
SELECT MyColumn + 100
In the above case if mycolumn is null then the result is NULL

Alternate solutions

SELECT 
        CASE WHEN MyColumn IS NULL 
                    THEN 0 
              ELSE MyColumn END 
FROM MyTable

SELECT ISNULL(mycolumn, 0)  + 100
FROM MyTable

Sunday, July 28, 2013

Where can I find IIS in Windows 7?

Before that you have to enable the IIS for windows by
  1. start
  2. Control panel
  3. programs
  4. Turn windows feature on / off
  5. Check the IIS services (4th and 5th checkbox)
  6. ok
  7. restart the system

Saturday, July 27, 2013

Create xml from database using LINQ

Create XML from Database

Suppose we have below table in database. Now I want to make xml of all the products which have stock greater than 0. Here I am using LINQ Pad to query data from the database. It is a great tool to query data from database using LINQ to SQL, LINQ to XML, LINQ to Entity Framework.
  1. CREATE TABLE Product (
  2. ProductID int IDENTITY(1,1) NOT NULL,
  3. ProductName varchar(50) NOT NULL,
  4. Price float NOT NULL,
  5. Stock int NOT NULL
  6. )
  7. GO
  8. INSERT INTO Product (ProductName,Price,Stock)VALUES('P001',12.12,100)
  9. INSERT INTO Product (ProductName,Price,Stock)VALUES('P002',102.12,200)
  10. INSERT INTO Product (ProductName,Price,Stock)VALUES('P003',104.12,500)
  11. INSERT INTO Product (ProductName,Price,Stock)VALUES('P004',108.12,100)
  12. INSERT INTO Product (ProductName,Price,Stock)VALUES('P005',72.12,10)
  13. INSERT INTO Product (ProductName,Price,Stock)VALUES('P006',72.12,0)
  14. GO
  15. SELECT * FROM Product

Now, query the data from above table using LINQ. We can also save the output to xml file.

  1. //Export above xml to xmlfile
  2. XElement.Save(Server.MapPath(@"~/export.xml"));

Difference between Var and IEnumerable

Var VS IEnumerable

In previous article I explain the difference between IEnumerable and IQuerableIEnumerable and IList. In this article I expose the difference between Var and IEnumerable. IEnumerable is an interface that can move forward only over a collection, it can’t move backward and between the items. Var is used to declare implicitly typed local variable means it tells the compiler to figure out the type of the variable at compilation time. A var variable must be initialized at the time of declaration. Both have its own importance to query data and data manipulation.

Var Type

Since Var is anonymous types, hence use it whenever you don't know the type of output or it is anonymous. Suppose you are joining two tables and retrieving data from both the tables then the result will be an Anonymous type.
  1. var q =(from e in tblEmployee
  2. join d in tblDept on e.DeptID equals d.DeptID
  3. select new
  4. {
  5. e.EmpID,
  6. e.FirstName,
  7. d.DeptName,
  8. });
In above query, result is coming from both the tables so use Var type.
  1. var q =(from e in tblEmployee where e.City=="Delhi" select new {
  2. e.EmpID,
  3. FullName=e.FirstName+" "+e.LastName,
  4. e.Salary
  5. });
In above query, result is coming only from single table but we are combining the employee's FirstName and LastName to new type FullName that is annonymous type so use Var type. Hence use Var type when you want to make a "custom" type on the fly.
More over Var acts like as IQueryable since it execute select query on server side with all filters. Refer below examples for explanation.

IEnumerable Example

  1. MyDataContext dc = new MyDataContext ();
  2. IEnumerable<Employee> list = dc.Employees.Where(p => p.Name.StartsWith("S"));
  3. list = list.Take<Employee>(10);

Generated SQL statements of above query will be :

  1. SELECT [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0] WHERE [t0].[EmpName] LIKE @p0
Notice that in this query "top 10" is missing since IEnumerable filters records on client side

Var Example

  1. MyDataContext dc = new MyDataContext ();
  2. var list = dc.Employees.Where(p => p.Name.StartsWith("S"));
  3. list = list.Take<Employee>(10);

Generated SQL statements of above query will be :

  1. SELECT TOP 10 [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0] WHERE [t0].[EmpName] LIKE @p0
Notice that in this query "top 10" is exist since var is a IQueryable type that executes query in SQL server with all filters.

IEnumerable Type

IEnumerable is a forward only collection and is useful when we already know the type of query result. In below query the result will be a list of employee that can be mapped (type cast) to employee table.
  1. IEnumerable<tblEmployee> lst =(from e in tblEmployee
  2. where e.City=="Delhi"
  3. select e);

Note

  1. Use Var type when you want to make a "custom" type on the fly.
  2. Use IEnumerable when you already know the type of query result.
  3. Var is also good for remote collection.
  4. IEnumerable is good for in-memory collection.