Showing posts with label Framework. Show all posts
Showing posts with label Framework. Show all posts

Find jQuery Errors in JS File

Find jQuery Errors in JS File

What is JSHint ?
  • It's a Tool to detect errors and potential problems in JavaScript code
  • Can be used to enforce coding conventions
  • Simple Tool that can very often spot your mistakes before you do
  • It can save you from a lot of tedious debugging
  • Lets you re-factor JavaScript code with greater confidence
  • It's reduces the chances of you deploying broken code to your production server

What does JSHint  do ?
  • It identifies definite, objective errors in your code
  • Such as mistyped keywords, mistyped variable names, mismatched parentheses, and other syntactical slip-ups
  • It enforces some basic code style consistency rules
  • Such as No trailing white space, no use of the == operator, etc.
  • Depending on how you configure JSHint  

How to Integrate JSHint with Visual Studio 2010 ?
Step 1. Open Visual Studio 2010

Step 2. Click  Tools  ===> Extension Manager



Step 3. Click "Online Gallery" Button


Step 4. Type "jslint" inside the Search box







Step 5. Click "Download" Button



Step 6. Click "Install" Button

Step 7. Click "Restart Now" Button for Restart Visual Studio 2010


That's It.You're Done.


How to Configure JSHint  ?

Step 1. Click  Tools  ===> JS Lint Options... on Visual Studio 2010 menu



Step 2. Click  "Visual Studio Options" and do necessary environmental adjustments
            are as below





Step 3. Click "JSLint Options" and Then select "JSHint" is as below




How to Configure Global Variables of jQuery and Knockout ?

Step : Click  "JSLint Options" and Then Type $ for jQuery and ko for Knockout inside the
           "Predefined Vars" Text box with separator as Comma (,)




That's It.You can Configure JSHint environment as you wish.


Let's do Small Demonstration

JsHintTest.js


function averageWeight(weights) {
  var sum = 0, index;
  for (index = 0; index < weights.length; index += 1) {
       sum += weights[index];
  }
   return sum / weights.length;
}
var myAverageWeight = averageWeight([1.75, 1.78, 1.82]);
Then Click View ==> Error List on Visual Studio 2010 Menu
After that, change the above function's Name as average and Parameter as values

JsHintTest.js file with Changes (with Errors)

function average(values) { // <-- This is the only line has been changed
    var sum = 0, index;
    for (index = 0; index < weights.length; index += 1) {
        sum += weights[index];
    }
    return sum / weights.length;
}
var myAverageWeight = averageWeight([1.75, 1.78, 1.82]);

  • Then try to Save (Ctrl+S) the JsHintTest.js file
  • After that It will show all the Errors are as below
You can see all the mistakes which you did by using JSHint very easily.
Would You Like to Test Your JS Code Online ?

Do You Need to Know More about JSHint ?



Conclusion
  • JSHint is best when you’re writing fresh new code
  • It needs a bit of configuration to give the best results
  • JSHint is reliable and sophisticated Tool for find errors on JavaScript code files
  • You could use JSHint for enforces some basic code style consistency rules 

I hope this helps to You.Comments and feedback greatly appreciated.
Continue Reading

Use Git with Visual Studio 2010

Use Git with Visual Studio 2010

What is GIT ?
  • In software development, Git is a distributed revision control and source code management (SCM) system with an emphasis on speed
  • Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.
  • Git is free software




For work with Git and VS 2010 You have to Down load and Install below mentioned Software.
(just click below mentioned hyper links)

1. Git Extensions

2.  Git Source Control Provider
   
    Note: for install Git Source Control Provider use below mentioned Steps :
              * Run Visual Studio.
              * Go to Tools | Extension Manager, Search Online Gallery for Git Source Control
                 Provider and  Install. (If you do above stepsthen you don't need to do any extra
                 configurations for this tool)

How to use GIT with VS 2010 ?

Step 1 :  Create a GIT Repository
   
              Select your Project by right click and then click "Create GIT Repository"


           

   

 













Then You can see Yellow Plus Symbols to denote that there are New Files.

Step 2 : Since I’m working on a New Project, I’ll Commit the New Files by using the 
             "Git Pending Changes" option as below. (right click your project)

Step 3 : Then you can select files which you want to Commit and give a meaningful Comment and 
             Press  Commit Button as below.
After that it Shows Added State as below.
Step 4 : When you set below mentioned Setup (TorticeGit Style) then generated Markers are very 
             easy to understand the status of files. 
Using VS 2010 : Tools --> Options --> Git Source Control Provider Options 
Colors Indicators :
Green   - Up to date
Yellow  - New File
Red      - Modified (not commit) 
Step 5 :  How to Modify a file and then Commit to Local Master ?

              Do modification to your file and then right click your project and click
              'Git Pending Changes'. It will show below screen.
              Right side of the below screen shows the changes done for the file.Its very useful 
              for double check the changes before Commit. 
Step 6 :  After Defining a Main Repository here  then Push your work for that Remote Repository 
              by clicking "Git Bash" short cut as below. 
Then you need to Type $ git push Your projects Remote Repository URL like below.
Then Username and Password for Remote Git Repository.
That is it.Now your codes are in Remote Git Repository.How easy it is. 
Other Important Git Functionalities
You can do all other Version Control related tasks such as pull,push,revert,commit,merge,stash etc. by using either Git Extensions or Tortoise Tool as below.
Select your project and then right click will popup below screen.
Important Note:
With Git Extention's  'Push' option is Not Working so far.So if you need to Push your code then You have to use either Git Bash (Command line utility which I showed early) or Tortoise Utilities.
Conclusion
  • By using above steps you can easily use Git with VS 2010
  • My Next Post about Git will explain how to Resolve Conflicts with Remote Repository by using inbuilt Tools in Git.
Continue Reading

Use Entity Framework Fluent API

Use Entity Framework Fluent API

How to Change Entity Framework Default Conventions, when Mapping Data ?

There are 3 ways.

1. Entity Framework Fluent API

2. Fluent Validation
       - Validation Library for .NET
       - This uses a fluent interface and lambda expressions for building validation rules
          for your business objects
3. Data Annotations 
          - Annotations only cover a subset of the Fluent Validation functionality


       
What is Entity Framework Fluent API ?
  • When working with Entity Framework Code First the default behavior is to map your POCO classes to tables using a set of conventions baked into Entity Framework
  • Sometimes, however you cannot or do not want to follow those conventions and need to map entities to something other than what the conventions dictate
  • For such a scenario you can use Fluent API
  • Can be Used Only with Code First Development
  • This is used to define the mapping between your objects and the database
What Does Fluent API  do ?
  • The Code First Fluent API is most commonly accessed by overriding the OnModelCreating method on your derived DbContext class
Which Tasks can be Achieved by using Fluent API ?
1. Property Mapping
2. Type Mapping

3. Configuring Relationships
On This Article I will explain Property Mapping with Fluent API.  
1. Property Mapping
    - is used to configure attributes for each property belonging to an entity or complex type
    - is used to obtain a configuration object for a given property
    - the options on the configuration object are specific to the type being configured
                 e.g. IsUnicode is available only on string properties 
  • How to Configure a Primary Key ?
          - The HasKey method is used to configure the InstructorID primary key on the
             OfficeAssignment type
       modelBuilder.Entity<OfficeAssignment>().HasKey(t => t.InstructorId);

  • How to Configure a Composite Primary Key ?
         - DepartmentId and Name properties to be the composite primary key of the
           Department type
      modelBuilder.Entity<Department>()
           .HasKey(t => new { t.DepartmentId, t.Name });

  • How to Switch off Identity for Numeric Primary Keys ?
         - DepartmentId property value will not be generated by the database
      modelBuilder.Entity<Department>()
          .Property(t => t.DepartmentId)
          .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

  • How to Specify the Maximum Length on a Property ?
         - Name property should be no longer than 50 characters

         - If you make the value longer than 50 characters, you will get a 
            DbEntityValidationException exception

         - If Code First creates a database from this model it will also set the
            maximum length of the Name column to 50 characters 

      modelBuilder.Entity<Department>().Property(t => t.Name).HasMaxLength(50);

  • How to Configure the Property to be Required ?
         - Name property is required

         - If you do not specify the Name, you will get a 
            DbEntityValidationException exception

         - If Code First creates a database from this model then the column used to store
            this property will be non-nullable
      modelBuilder.Entity<Department>().Property(t => t.Name).IsRequired(); 
  • How to Specify Not to Map a CLR Property to a Column in the Database ?

      modelBuilder.Entity<Department>().Ignore(t => t.Budget);

  • How to Map a CLR Property to a Specific Column in the Database ?

          - Maps the Name CLR property to the DepartmentName database column
       modelBuilder.Entity<Department>()
                .Property(t => t.Name)
                .HasColumnName("DepartmentName");

  • How to Rename a Foreign Key That Is Not Defined in the Model ?
          - If you choose not to define a foreign key on a CLR type,
          - But want to specify what name it should have in the database
       modelBuilder.Entity<Course>()
          .HasRequired(c => c.Department)
          .WithMany(t => t.Courses)
          .Map(m => m.MapKey("ChangedDepartmentId"));
  • How to Configure whether a String Property Supports Unicode Content ?
          - By default strings are Unicode (nvarchar in SQL Server)
          - You can use the IsUnicode method to specify that a string should be of varchar type
      modelBuilder.Entity<Department>().Property(t => t.Name).IsUnicode(false);

  • How to Configure the Data Type of a Database Column ?
         - The HasColumnType method enables mapping to different representations
            of the same basic type

         - Using this method does not enable you to perform any conversion
            of the data at run time

         - Note that : IsUnicode is the preferred way of setting columns to varchar,
            as it is database agnostic
     modelBuilder.Entity<Department>()
                 .Property(p => p.Name)
                 .HasColumnType("varchar");
  • How to Configure Properties on a Complex Type ?

         Way 1 : You can call Property on ComplexTypeConfiguration

       modelBuilder.ComplexType<Details>()
                   .Property(t => t.Location)
                   .HasMaxLength(20);

        Way 2 : You can also use the dot notation to access a property of a complex type

       modelBuilder.Entity<OnsiteCourse>()
            .Property(t => t.Details.Location)
            .HasMaxLength(20);

  • How to Configure a Property to Be Used as an Optimistic Concurrency Token ?

       Way 1 : You can use either the ConcurrencyCheck attribute
                     or the IsConcurrencyToken method
      modelBuilder.Entity<OfficeAssignment>()
                  .Property(t => t.Timestamp)
                  .IsConcurrencyToken();
      Way 2 : You can also use the IsRowVersion method
     modelBuilder.Entity<OfficeAssignment>()
                 .Property(t => t.Timestamp)
                 .IsRowVersion();

Conclusion
  • You can use Fluent API with Code First development, when you want to override the default conventions maintained by the Entity Framework
  • I will explain Type Mapping and Configuring Relationships with my future Blog Post
  • So Try This and Enjoy it

I hope this helps to You.Comments and feedback greatly appreciated.
Continue Reading

New in Entity Framework 5

New in Entity Framework 5

What is New in Entity Framework 5 ?

    1. Enum Support 
             - allows you to have enum properties in your entity classes (await for next post ...)

    2. Spatial Data Types
             - can now be exposed in your model using the DbGeography and DbGeometry
               data types (await for next post ...)

    3. Performance Enhancements
        i. LINQ to Entities Query Repeat Execution Time
           - repeat execution time of the same LINQ query has been reduced by around 600%
           - by using automatic compilation of LINQ to Entities queries

                    What is automatic compilation ?
                         - now every LINQ to Entities query that you execute automatically
                           gets compiled and placed in EF’s query cache
                         - each additional time you run the query, EF will find it in its query cache
                            and won’t have to go through the whole compilation process again

                    Behind the scene of Auto-Compiled Query Process in EF 5



               Performance gain of EF 5 Hence Auto-Compiled Query Process


           
        ii. End-to-End Performance
                - performance tests that run a variety of operations designed to simulate the
                   typical usage a real-world application
                - then 67% performance increase over EF 4
                - just by upgrading the server to EF 5

"We aren’t done improving performance yet, but we’re excited about how much faster EF 5.0 is"
- The Microsoft Entity Framework Team

     4. Code First will now detect if you have LocalDb available for creating new databases
             - visual studio 2012 includes LocalDb

                     What is LocalDb ?
                        - Microsoft SQL Server 2012 Express LocalDB is an execution mode
                          of SQL Server Express targeted to program developers
                        - LocalDB installation copies a minimal set of files necessary to start the
                          SQL Server Database Engine


     5. Code First will add tables to existing database
            - if the target database doesn’t contain any of the tables from the model
What is New in Entity Framework Designer in Visual Studio 2012 ?

     1. DbContext code generation for new models
           - means that any new models created using the EF Designer will generate
              a derived DbContext and POCO classes by default
           - you can always revert to ObjectContext code generation if needed
           - existing models will not automatically change to DbContext code generation

     2. Multiple-diagrams per model
           - allows you to have several diagrams that visualize subsections of your overall model
           - shapes on the design surface can also have coloring applied

     3. Table-Valued functions
           - in an existing database can now be added to your model

     4. Batch import of Stored Procedures
          - allows multiple Stored Procedures to be added to the model during model creation
How to Install Entity Framework 5 for Visual Studio 2012 Solution ?

Step 1. Open Visual Studio 2012 with Your project

Step 2. Right Click Your Solution and then Click Properties

Step 3. Double check whether Your Target Framework is 4.5
Step 4. Right Click Your Solution and then Click Manage NuGet Packages... 
Step 5. Click Online Tab and Then Type Entity Framework 5 on Search Box
            After that Select EntityFramework and Click Install 
Step 6. Click I Accept
Step 7. Finally, Close the Manage NuGet Packages Screen
That's It.You're Done.
Conclusion
  • You saw that how much of performance gain could be achieved by just updating the Application Server for Entity Framework 5 Out of the box without doing anything to your existing Linq to Entity Queries
  • It's Simply Amazing
  • So Try to use EF 5 with your projects and Enjoy it

I hope this helps to You.Comments and feedback greatly appreciated.
Continue Reading