Thursday, November 30, 2017

LINQ: Language Integrated Query

LINQ is an acronym for Language Integrated Query. The Language Integrated part means that it is part of programming language syntax, and Query means, as it explains - is a means to retrieve data from a data source.

To retrieve data from different/multiple data sources in .NET, the underlying query languages use are:

  • SQL and ADO.Net for relational databases
  • XQuery and XSLT for XML

LINQ simplifies this working model by providing a common platform to execute the query and get the results. Basically LINQ query always works with objects, so the basic coding to query and transform data in XML, SQL database, ADO.NET Datasets, Collections and any other format for which LINQ provider available is common.

LINQ Archiecture

Below are different Types of LINQ:

  • LINQ to Objects
  • LINQ to XML (XLINQ)
  • LINQ to Dataset
  • LINQ to SQL (DLINQ)
  • LINQ to Entites

LINQ Syntax: Following are the two ways of LINQ syntaxes:

  • Lamda (Method) Syntax:
  • var testWords = words.where(w => w.length >10);
  • Query (Comprehension) Syntax:
  • var testWords = (from word in words where w.length > 10);

Per MSDN, Query expression consists below clauses:

  • FROM refers to Data Source
  • WHERE takes care of Filtering the requirement
  • SELECT takes responsibility of elements to return

Below are the Advantages and Disadvantages of using LINQ:

Advantages:
  • LINQ can be used against different data sources and it is not limited to RDBMS
  • Viewing table relationships is easy due to its hierarchical feature, which also enables composing queries by joining multiple table in less time
  • LINQ allows a single syntax while querying different data sources with support of its unitive foundation
  • LINQ is extensible, mean it is possible to use LINQ to query new data sources
  • A single LINQ query can join several data sources
  • Easy transformation for conversion of one data type to another, ex: SQL data to XML data
  • Debugging is easy due to its integration in C#
  • Writing more accurate queries is easy using LINQ intellisense
  • LINQ queries are typesafe as the errors will be type checked at compile time
Disadvantages:
  • For every query change, assembly needs to be recompiled and deployed
  • LINQ queries are not precompiled so need to take extra cautions to handle performance
  • In given scenarios, it is hard to understand advance LINQ queries
  • There will always be some things you can do in SQL but not in LINQ
With this I am concluding the illustration. Feel free to share your feedback.

Happy Programming !!!

URL Rewrite

URL Rewrite is the process of altering the parameters in a URL (Uniform Resource Locator). The URL rewrite module is an extension to IIS which is available as a download for your stand-alone IIS Server. URL Rewrites can be managed at the server level or for individual sites as required.

Patterns are used through the URL Rewrite module. These are in one of three modes:
  • Exact Match
  • Wildcards - where an asterisk is used to mean "anything here" and is captured when matched
  • ECMAScript regular expressions, which are Perl compatible regular expressions

Rules are two types as below:
  • Inbound rules - looks at the request URLs and change them
  • Outbound rules - inspects the traffic sent out, look for URLs within it, and rewrite them as needed. This is very handy when the content may use an absolute URL that is not what the user should be receiving (especially handy in reverse proxy scenarios)

Built in Rules URL rewrite supports various built in rules as below:
  • Rule with rewrite map: allows you to define a set of paths and their replacements as a simple list
  • Request blocking: disallow access to a path
  • User-friendly URL: quickly creates rules to map path segments (separated by slashes) to query strings
  • Reverse Proxy: allows the current server to reverse proxy another
  • Enforce lowercase URLs: makes the client always use lowercase URLs via an HTTP status 301 ("Permanent") redirect
  • Canonical domain name: uses an HTTP status 301 ("Permanent") redirect to ensure that clients always use the specified domain name
  • Append or remove the trailing slash symbol: will either always add or always remove the trailing slash in an URL path using an HTTP status 301 ("Permanent") redirect