Translate

Wednesday 24 February 2016

MERGE SQL Server

1. it is an efficient way to perform multiple DML operations.

2. the most important advantage of MERGE statement is all the data is read and processed only once.

3. using MERGE statement we can include the logic of such data modifications in one statement that even checks when the data is matched then just update it and when unmatched then insert it.

4. This is quite an improvement in performance of database query.

Example,
-- Update existing, add missing
MERGE INTO dbo.tbl_Customers AS C
USING dbo.tbl_CustomersTemp AS CT
        ON C.CustID = CT.CustID
WHEN MATCHED THEN
    UPDATE SET
      C.CompanyName = CT.CompanyName,
      C.Phone = CT.Phone
WHEN NOT MATCHED THEN 
      INSERT (CustID, CompanyName, Phone)
      VALUES (CT.CustID, CT.CompanyName, CT.Phone)

CREATE TABLE dbo.tbl_Source (id INT, name NVARCHAR(100), qty INT);
CREATE TABLE dbo.tbl_Target (id INT, name NVARCHAR(100), qty INT);

--Synchronize source data with target
MERGE INTO dbo.tbl_Target AS t
    USING dbo.tbl_Source AS s    
        ON t.id = s.id
    WHEN MATCHED AND (t.name != s.name OR t.qty!= s.qty) THEN
        --Row exists and data is different
        UPDATE SET t.name = s.name, t.qty = s.qty
    WHEN NOT MATCHED THEN 
        --Row exists in source but not in target
        INSERT VALUES (s.id, s.name, s.qty) 
    WHEN SOURCE NOT MATCHED THEN 
        --Row exists in target but not in source
        DELETE OUTPUT$action, inserted.id, deleted.id

Thursday 18 February 2016

Factory pattern Vs Abstract Factory pattern

Factory

Definition:

Define an interface for creating an object, but let the classes that implement the interface decide which class to instantiate.

Real Life Example,

Imagine you are constructing a house and you approach a carpenter for a door. You give the measurement for the door and your requirements, and he will construct a door for you. In this case, the carpenter is a factory of doors. Your specifications are inputs for the factory, and the door is the output or product from the factory.

Abstract Factory

Definition:

Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

Real Life Example,


Now, consider the same example of the door. You can go to a carpenter, or you can go to a plastic door shop or a PVC shop. All of them are door factories. Based on the situation, you decide what kind of factory you need to approach. This is like an Abstract Factory.

Sunday 14 February 2016

.NET Framework 4 - New Features

Introduction:
The .NET Framework 4 introduces an improved security model, APIs, workflow models, inbuilt plug-in, workflow and VS designer for attract to end-users

Here they introduced many new features and environment,
  • Security Changes in the .NET Framework 4.
  • Application Compatibility and Deployment
  • Web
  • Client - Enhancements in WPF
  • Data
  • Communications and Workflow
Security Changes in the .NET Framework 4 :

They implemented two major changes in security the code that calls security policy APIs receives a NotSupportedException in addition to compiler warnings at run time and also they invoked obsolete request permissions.
  • Machine-wide security policy
  • Security transparency
Application Compatibility and Deployment

The .NET Framework 4 does not automatically use its version of the common language runtime to run applications that are built with earlier versions of the .NET Framework. To run older applications with .NET Framework 4, you must compile your application with the target .NET Framework version specified in the properties for your project in Visual Studio, or you can specify the supported runtime with the <supportedRuntime> Element in an application configuration file.
New features:
  • Diagnostics and Performance
  • Garbage Collection
  • Code Contracts
  • Design-Time-Only Interop Assemblies
  • Dynamic Language Runtime
  • Memory-Mapped Files
Features in Web:
  1. Web Forms controls, including a new Chart control.
  2. Microsoft Ajax, including additional support for client-based Ajax applications in the Microsoft Ajax Library.
  3. Multi-targeting, including better filtering for features that are not available in the target version of the .NET Framework.
  4. Web Forms, including more integrated support for ASP.NET routing, enhanced support for Web standards, updated browser support, new features for data controls, and new features for view state management.
  5. MVC, including new helper methods for views, support for partitioned MVC applications, and asynchronous controllers.
  6. Deployment, including new tools for automating typical deployment tasks.
  7. MVC, including new helper methods for views, support for partitioned MVC applications, and asynchronous controllers.
Enhancements in WPF:
  1. New Controls,
    1. DataGrid
    2. Calendar
    3. DatePicker
  2. Visual State Manager.
  3. Touch and Manipulation.
  4. Graphics and Animations,
    1. Layout Rounding
    2. Cached Composition
    3. Pixel Shader 3 Support
    4. Easing Functions
  5. Text,
    1. New Text Rendering Stack
    2. Selection and Caret Customization
  6. Binding,
    1. XAML Browser Applications
    2. HTML-XBAP Script Interop
    3. Full-Trust XBAP Deployment
  7. WPF and Windows.
  8. WPF and Silverlight Designer
    1. Improved Support for Silverlight.
    2. Support for Multiple Platform Versions.
    3. Visual Databinding.
    4. Auto Layout.
    5. Improved Property Editing.
    6. The Properties window now enables visually creating and editing Brush resources.
DATA:
  1. ADO.NET
    1. Foreign Keys in the Conceptual Model.
    2. New Methods for N-Tier Application Development.
    3. EntityDataSource Support for the QueryExtender Control.
    4. Testability with IObjectSet<T>.
    5. Direct Execution of Store Commands
    6. Persistence-Ignorant Objects.
    7. Lazy Loading of Related Objects.
    8. Functions in LINQ to Entities Queries.
    9. OrderBy Improvements in LINQ to Entities.
    10. Customized Object-Layer Code Generation.
    11. Model-First Support.
    12. Complex Type Support.
    13. Naming Service.
    14. Improved Model Browser Functionality.
    15. Entity Designer Extensibility.
    16. Entity Data Model Documentation.
  2. Dynamic Data
    1. Automatic validation that is based on constraints that are defined in the data model.
    2. The ability to easily change the markup that is generated for fields in the GridView and DetailsView controls by using field templates that are part of a Dynamic Data project.
Communications and Workflow:
  1. WCF
    1. Configuration Based Activation.
    2. System.Web.Routing Integration.
    3. Multiple IIS Site Bindings Support.
    4. Routing Service.
    5. Support for WS-Discovery.
    6. Standard Endpoints.
    7. Workflow Services.
    8. Target Framework Attribute.
  2. WorkFlow
    1. Workflow Activity Model.
    2. Rich Composite Activity Options.
    3. Expanded Built-In Activity Library.
    4. Explicit Activity Data Model.
    5. Enhanced Hosting, Persistence, and Tracking Options.
    6. Easier Ability to Extend WF Designer Experience.