Friday, August 31, 2012

How to Disable a Button Using Jquery and CSS ?


How to Disable a Button ? :


Disable a Button Using Jquery and CSS


Step 1:

Using Jquery attr Attribute :

$('.actionButton').attr('disabled', 'disabled');

Step 2:

Using Jquery addClass CSS Class :

$('.actionButton').addClass('disabled');

Step 3:

Then by Declaring CSS Style Class :

    <style type="text/css">
        .disabled
        {
            background: none repeat scroll 0 0 burlyWood;
            cursor: default !important;
        }
    </style>

Note : Important thing here is you have to give proper cursor style like above when button is in Disable State

How to Enable a Button Again ? :

Step 1 :

Using Jquery removeAttr Attribute :

$('.actionButton').removeAttr('disabled');

Step 2 :

Using Jquery removeClass CSS Class :

$('.actionButton').removeClass('disabled');

Conclusion
You can Disable or Enable a button which was disable earlier by using above methods easily.

Happy Coding.


Monday, August 27, 2012

How to Convert Linq Entity Query into T-SQL ?


Why Should We Convert ?

1. We all know we are better T-Sql professionals than quite new Entity framework.Hence by converting entity query into T-Sql, we can understand what's going on when it runs on SQL Server better.

2. We can use generated T-Sql query to identify the Index Keys for tables which are needed for gain more performance.(as an input for Database Engine Tuning Adviser- my next blog-post will explain how to do)

3. By studying those generated T-Sql we can improve our Entity query for better performances (using SQL Server Execution Plans etc.).

How To Do That?

Method 1 :

You can use LINQPad.It's Free http://www.linqpad.net/
(Note: my next blog-post will explain how to configure LinqPad with Visual Studio )

LINQPad

































Method 2 :

You can use SQL Server Profiler inside the Sql Server (Tools --> SQL Server Profiler)


SQL Server Profiler

Method 3 :

You can use Visual Studio Debugger for Generate T-Sql.(with any visual studio version)

Visual Studio Debugger

Note: One thing I need to mention here is After request the data from Database Server by using FirstOrDefault() , ToList() ,etc then you cannot use above method.So you have to investigate T-Sql Before calling it to the Database server (the way I showed in above image).

Conclusion
You can use one of the above method to investigate the T-Sql generation from EF Query Without using High Paid 3rd party tools or Visual Studio Ultimate edition.

Happy Coding.


May Be Use Full To You :
How to Enable jQuery Intellisense in Visual Studio 2010 ?
How to Disable a Button Using Jquery and CSS ?
How to Improve Performance of Entity Framework Query (over 400 times)?

Monday, August 20, 2012

How to Improve Performance of Entity Framework Query ?

What is Eager Lording?
  • When using Eager Loading, the related entities are loaded along with your target entity set
  • You use an Include statement in your query to indicate which related entities you want to bring in

Bad way of using Eager Loading
  • Single Call for Database Server with Many Include - BAD

public Invoice GetInvoice(string providerKey, string ownerKey, Guid id)
        {
            return (from owner in Catalog.Owners
                    where owner.Key == ownerKey
                    from invoice in owner.Invoices
                    where invoice.Provider.Key == providerKey
                    where invoice.Id == id
                    select invoice)
                    .Include(i => i.Owner.Credits)
                    .Include(i => i.Provider)
                    .Include(i => i.Items.Select(s => s.Allocation.Service))
                    .Include(i => i.Items.Select(s => s.Allocation.Pet))
                    .FirstOrDefault();
        }


Before breaking the query: Time for load the data  ~ 17 s

Before breaking the query

Best way of using Eager Loading
  • 2 or More Small Data Request from Database Server - BEST

public Invoice GetInvoice(string providerKey, string ownerKey, Guid id)
        {
            //split the eager method(Include) for better performances 
            var invoiceObject = (from owner in Catalog.Owners
                                 where owner.Key == ownerKey
                                 from invoice in owner.Invoices
                                 where invoice.Provider.Key == providerKey
                                 where invoice.Id == id
                                 select invoice)
                                 .Include(i => i.Owner.Credits)
                                 .Include(i => i.Provider)
                                 .FirstOrDefault();

            invoiceObject = (from owner in Catalog.Owners
                             where owner.Key == ownerKey
                             from invoice in owner.Invoices
                             where invoice.Provider.Key == providerKey
                             where invoice.Id == id
                             select invoice)
                             .Include(i => i.Items.Select(s => s.Allocation.Service))
                             .Include(i => i.Items.Select(s => s.Allocation.Pet))
                             .FirstOrDefault();

                 return invoiceObject;
        }

After breaking the query: Time for load the data ~ 0.038 s

After breaking the query

Performance Boost ~ Over 400 times than before

I have used JetBrains dotTrace Performance Tool for do the above Testing.

Do you Need to know more about JetBrains dotTrace ?


JetBrains dotTrace


Are You an Entity Framework Lover ?


 Entity Framework 5



Conclusion
  • If you would like to use Eager loading method for data loading with entity framework then use brake query method
  • Don’t use more than 2 Includes on single query (MAX = 2 Includes per Query)
  • Break them as above for better performances
  • It will give Over 400X performance gain

P.S.

In detail Answers for Comments Posted by Anonymous September 6, 2012 12:23 AM and
Anonymous September 9, 2012 7:27 AM Developers :

Part 1 : 

You can see that when I ran the first part of the invoiceObject by using debuger it generated Dynamic Proxy for Provider object But Not for the Items List object. 


Dynamic Proxy for Provider object







                            
Part 2 : 

In below screen you can see it Generated Data for Items List object But Nothing Happened to the Provider Object which was generated earlier (Your override concept is not happening here.Because 2 Sub queries are Merged by using Union. Theses are not happening like basic programming concepts.Its generating T-Sql by using Dynamic Proxies.).Because of that in this methodology (BEST) is giving Same Out Put as Earlier one (BAD) but Very Very Speedy way.(400 times faster than BAD scenario) 


Nothing Happened to the Provider Object













 
                       

Happy Coding.

May Be Use Full To You :