Sunday, December 11, 2011

Difference Between SQL Functions and Stored Procedure


StoredProcedure Functions


StoredProcedure has out parameter Functions doesn't have any out parameter
It will return value datatype must be integer It will return value as any datatype
including the user defined datatype
except BLOB, cursor and time stamps
Return value is used as indication whether
execution was success or failure
Unlike stored procedure return value
is to serve a meaningful piece of data
Return value can't used directly in query,
 it has to be stored somewhere before
it's used in query
Return value can be used directly in
query as result.
Stored Procedure will return scalar value Storedprocedure will return scalar value as table



Thursday, October 13, 2011

Difference between ASP.NET Web Service and WCF

"width: 284pt;" width="378">

WCF 

ASP.Net Web Service
Data Representation

DataContractSerialier

XMLSerializer

very precise control over how a type is represented in XML

very little control over how a type is represented in XML

Not much control over the type serialization process becomes highly predictable for the DataContractSerializer, and, thereby, easier to optimize A practical benefit of the design of the DataContractSerializer
 is better performance, approximately ten percent better
performance.

DataMemberAttribute for use with the DataContractSerializer shows explicitly which fields or properties are serialized

We can't specify which fields or properties of the type are  serialized into XML

the DataContractSerializer can translate the members of
objects into XML regardless of the access modifiers of those members.

The XmlSerializer can only translate the public members
of a .NET object into XML

the DataContractSerializer has fewer restrictions on the
variety of .NET types that it can serialize into XML.
In particular, it can translate into XML types
like
Hashtable that implement the IDictionary interface

Classes that implement the IDictionary interface, such as
Hashtable, cannot be serialized into XML.
Hosting

the service file have .svc extension

#@ServiceHost

IIS, WAS, .NET application

the service file have .ASMX extension

#@WebService

IIS


Client development

servicemodel metadata utility tool (svcutil.exe)

Web service definition language (WSDL.exe)


Message Representation

SOAP message can be customized by MessageHeader,
MessageContract, MessageBodyMember

SOAP message can be customized by SoapHeader,
SOAPheaderAttribute


Service Description

WSDL generation of WCF can be customized not generate
instead use existing static WSDL itself

WSDL generation of ASP.NET can't be customized not generate 


Exception Handling

In WCF services, unhandled exceptions are not returned
to clients as SOAP faults to prevent sensitive information being inadvertently exposed through the exceptions.

In ASP.NET Web services, unhandled exceptions are
returned to clients as SOAP fault


State Management

The WCF provides extensible objects for state management.
 Extensible objects are objects that implement
IExtensibleObject. The most important extensible objects
are ServiceHostBase and InstanceContext. ServiceHostBase
 allows you to maintain state that all of the instances of all
 of the service types on the same host can access, while
InstanceContext allows you to maintain state that can
be accessed by any code running within the same
instance of a service type.

ASP.NET provides considerable control over where the
session state information accessed by using the Session
property of the HttpContext is actually stored.
It may be stored in cookies, in a database, in the memory
of the current server, or in the memory of a designated
server. The choice is made in the service’s configuration file.


Globalization

The WCF does not support that configuration setting
except in ASP.NET compatibility mode.
To localize a WCF service that does not use ASP.NET compatibility mode, compile the service type into culture-specific assemblies, and have separate culture-specific endpoints for each culture-specific assembly. 

The ASP.NET configuration language allows you to specify
the culture for individual services









Saturday, August 27, 2011

LINQ to SQL


LINQ – Language integrated query
It’s allows the programmer to express query behavior in their programming language of choice. It provide type safety and compile time valuation of expression.
LINQ supports three data source objects, XML and databases.
LINQ to SQL allows to represent the database objects in .Net classes, you can query the database as well as update/delete/insert the data.
It supports views, stored procedure and transactions, allows the integration validation logic into data model.
DataContext Class
For each LINQ to SQL class, there will be custom datacontext class will be generated. Properties will be added for each table and stored procedure we added into LINQ to SQL design surface.Datacontext is main conduit from which we query our entities from database.

            //Connnection to database.
            AdventureWorksDataContext db = new AdventureWorksDataContext();

            //Query the datamodel through query.
            var query = from p in db.Products
                        select p;

            //Result of query
            this.grid.datasource = query;

            //Update/insert/delete change into database.
            db.SubmitChanges();

Summary

LINQ to SQL provides a nice, clean way to model the data layer of your application.Once you've defined your data model you can easily and efficiently perform queries, inserts, updates and deletes against it. 

Wednesday, July 6, 2011

LINQ-Language INtegrated Query

LINQ-Language integrated Query, new language library which can be used to Query the Implementation of interface's IEnumerable, List, T[], HashSet.

Normally LINQ methods are supplied with Lambas expression, Anonymous methods and normal methods.

LINQ methods are classified into Different category.

  • Chiaining – (Where, Select)
  • Combine and Reduce – (Concat, Distinct, Union)
  • First and Match – (First , FirstOrDefault)
  • Other and Match – (Last, ElementAt, Single)
  • Set – (Except, Intersect, Union)
  • Membership and Count – (Contains, Count)
  • Aggregate – (Sum, Avarage, Min, Max, Aggregate)
  • Grouping – (GroupBy)
  • Ordering – (OrderBy, OrderByDescending, ThenBy, ThenBydescending)
  • Export – (ToArray, ToList, ToDictionary, ToLookup)
For more information on MSDN - http://msdn.microsoft.com/en-us/netframework/aa904594

Sunday, March 6, 2011

SQL Server 2008 Joins

Joining is basic functionality of SQL Server to get the results combine of more than one table. There are three types of joinings
1) CROSS JOIN
CROSS JOIN is Cartesian product of both table records.
i) SELF JOIN
SELF JOIN is Cartesian product of same table records.
2) INNER JOIN
INNER JOIN is Cartesian product + Filter predicate on ON
i) COMPOSITE JOIN
COMPOSITE JOIN is Cartesian product + Filter predicate on more than on attribute on joins tables
ii) NON-EQU JOIN
NON-EQU JOIN is Cartesian product + Filter predicate on ON with not equal operator
iii) MULTI TABLE JOIN
MULTI TABLE JOIN is Cartesian product + Filter predicate on ON with more than one table and joining applies from left to right direction.
3) OUTER JOIN
OUTER JOIN is Cartesian product + Filter predicate on ON + Add outer rows(Rows from preserved table)
i) LEFT OUTER JOIN
LEFT OUTER JOIN is Cartesian product + Filter predicate on ON + Add outer rows(Rows from LEFT preserved table)
ii) RIGHT OUTER JOIN
RIGHT OUTER JOIN is Cartesian product + Filter predicate on ON + Add outer rows(Rows from RIGHT preserved table)
iii) FULL OUTER JOIN
FULL OUTER JOIN is Cartesian product + Filter predicate on ON + Add outer rows(Rows from BOTH preserved table)

Write what you want to say about this article.