Saturday, 12 July 2014

Inner Join Example in LINQ and C#

Let see an example of using the Join method in LINQ and C#. The Join method performs an inner equijoin on two sequences, correlating the elements of these sequences based on matching keys. It is called equijoin, since we are testing for equality using the equals operator.
If you are familiar with relational databases, then in an inner join, each element of the first collection appears one time for every matching element in the second collection. If an element in the first collection has no matching elements, it does not appear in the join result set. The Join method in LINQ does the same.
We will using two classes Book and Order and use the Join operator on them and see the results. Here’s some sample data:
class Program

{

    static void Main(string[] args)

    {

        List<Book> bookList = new List<Book>

        {

            new Book{BookID=1, BookNm="DevCurry.com Developer Tips"},

            new Book{BookID=2, BookNm=".NET and COM for Newbies"},

            new Book{BookID=3, BookNm="51 jQuery ASP.NET Recipes"},

            new Book{BookID=4, BookNm="Motivational Gurus"},

            new Book{BookID=5, BookNm="Spiritual Gurus"}

        };



        List<Order> bookOrders = new List<Order>{

            new Order{OrderID=1, BookID=1, PaymentMode="Cheque"},

            new Order{OrderID=2, BookID=5, PaymentMode="Credit"},

            new Order{OrderID=3, BookID=1, PaymentMode="Cash"},

            new Order{OrderID=4, BookID=3, PaymentMode="Cheque"},

            new Order{OrderID=5, BookID=3, PaymentMode="Cheque"},

            new Order{OrderID=6, BookID=4, PaymentMode="Cash"}

        };

    }

}



public class Book

{

    public int BookID { get; set; }

    public string BookNm { get; set; }

}



public class Order

{

    public int OrderID { get; set; }

    public int BookID { get; set; }

    public string PaymentMode { get; set; }

}
Let us apply a Join between Book and Order collection
var orderForBooks = from bk in bookList

            join ordr in bookOrders

            on bk.BookID equals ordr.BookID

            select new

            {

                bk.BookID,

                Name = bk.BookNm,

                ordr.PaymentMode

            };



foreach (var item in orderForBooks)

    Console.WriteLine(item);



Console.ReadLine();
In the code shown above, the query uses the join clause to match Book objects with Order objects testing it for equality using the equals operator.The select clause defines how the result will appear using anonymous types that consist of the BookID, Book Name and Order Payment Mode.
OUTPUT

LINQ join
As you can see, ‘DevCurry.com Developer Tips’ and ‘Spiritual Gurus’ are listed twice as the books have two orders each. However ‘.NET and COM for Newbies’ does appear in the results, since there are no orders for that book.
In this example, we saw how to do an Inner Join in LINQ. In an upcoming article, we will see how to do a Left Outer Join in LINQ.

Why use web services?

Web services are also great to share data between multiple applications.


For example if you have a domain and services layer you may create a server that your website, andoird/iphone app, and console application may access without duplicating your business logic.
Basically it will be for retrieving data and then let your application decide what to do with that data.

Use web services instead of C# classes in following cases
  1. You want to expose some functionality to outsideworld/consumers/other applications
  2. You want to decouple parts ofyour system so that they can be changed without affecting otherparts of application
  3. You want to do make your application scaleable,so you create webserices and deploy those on different servers

What is CDC (Change data capture) in SQL Server?

Change data capture helps to capture insert, update and delete activity in SQL Server.

 Enabling CDC is a two-step process:-

The first step is to fire exec "sp_cdc_enable_db" and enable CDC on database level.


Once CDC is enabled on a database level, we need to also specify which tables needs to be enabled for CDC. Below is a simple code snippet which shows how "Sales" table has been enabled for CDC.


Once CDC is enabled, you will find the below tables created for CDC. The most important table is _CT table. For example you can see the below image, for the sales table it has created "dbo_Sales_CT" table.





Now if we modify any data in the "Sales" table the "Sales_CT" table will be affected. After any modification on the "Sales" table, in "Sales_CT" table we will get two rows one with the old value and the other with new value. Below image shows that "Rajendra" has been modified to "Raju" in the "Sales" table.



If you see the _CT table it has a column called as"_$operation". This field will help us identify what kinds of transactions are done with the data. Below are the possible values depending on operation done on the data:-



  • Delete Statement = 1

  • Insert Statement = 2

  • Value before Update Statement = 3

  • Value after Update Statement = 4


Friday, 11 July 2014

In GridView Textbox only take number in Javascript


    <script type="text/javascript" language="javascript">
 function checkDec(el){
 var ex = /^[0-9]+\.?[0-9]*$/;
 if(ex.test(el.value)==false){
   el.value = el.value.substring(0,el.value.length - 1);
  }
}
    </script>
//InGridView  (Onkey up



                                                                 <asp:TextBox ID="txtInsurance"  onkeyup ="checkDec(this);"  Width="80px" Text='<%# Eval("InsurancePrice", "{0:N}")%>'
                                                                    runat="server" />

Flux Slider jQuery plugin

Today I will make review (example of implementation) of fresh and cool slider plugin – Flux. This slider using CSS3 animation with great transition effects (like: bars, zip, blinds, blocks, concentric, warp). And, what is most great – now it can support 3D transitions too (bars3d, cube, tiles3d, Blinds3D effects). Of course, not all browsers support 3D transitions (I tested in Chrome – can confirm that it working here).
Here are list of supported browsers:
  • Chrome
  • Firefox 4
  • iOS
  • Opera 11
  • Safari

Firstly – you can download our package:

Download