Contents tagged with ASP.NET

  • Getting Started with NHibernate and ASP.NET MVC- CRUD Operations

    In this post we are going to learn how we can use NHibernate in ASP.NET MVC application.

    What is NHibernate:

    Nhibernate

    ORMs(Object Relational Mapper) are quite popular this days. ORM is a mechanism to map database entities to Class entity objects without writing a code for fetching data and write some SQL queries. It automatically generates SQL Query for us and fetch data behalf on us.

    NHibernate is also a kind of Object Relational Mapper which is a port of popular Java ORM Hibernate. It provides a framework for mapping an domain model classes to a traditional relational databases. Its give us freedom of writing repetitive ADO.NET code as this will be act as our database layer. Let’s get started with NHibernate.

    How to download:

    There are two ways you can download this ORM. From nuget package and from the source forge site.

    1. Nuget - http://www.nuget.org/packages/NHibernate/
    2. Source Forge-http://sourceforge.net/projects/nhibernate/

    More on my personal blog

    Shout it

  • Deferred vs Immediate execution in Linq

    In this post, We are going to learn about Deferred vs Immediate execution in Linq.  There an interesting variations how Linq operators executes and in this post we are going to learn both Deferred execution and immediate execution.

    What is Deferred Execution?

    In the Deferred execution query will be executed and evaluated at the time of query variables usage. Let’s take an example to understand Deferred Execution better.

    Example:

    Following is a code for that.

    using System;
    using System.Collections.Generic;
    using System.Linq;

    namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var customers = new List<Customer>( new[] { new Customer{FirstName = "Jalpesh",LastName = "Vadgama"}, new Customer{FirstName = "Vishal",LastName = "Vadgama"}, new Customer{FirstName = "Tushar",LastName = "Maru"} } );

            var newCustomers = customers.Where(c =&gt; c.LastName == &quot;Vadgama&quot;);
    
            customers.Add(new Customer {FirstName = &quot;Teerth&quot;, LastName = &quot;Vadgama&quot;});
    
            foreach (var c in newCustomers)
            {
                Console.WriteLine(c.FirstName);
            }
        }
    
        public class Customer
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
        }
    
    }
    

    }

    More on my personal blog @www.dotnetjalps.com

    Shout it

  • Extending jQuery with jQuery.Extend

    We all know that jQuery is a great JavaScript framework. It’s provide lots of functionalities and most used framework in programming world. But sometimes we need a functionality that does not provided by jQuery by default. At that time we need to extend jQuery. We can extend jQuery with jQuery.Extend  Method. You can get complete information from the following link.

    http://api.jquery.com/jQuery.extend/

    It merges the contents of two or more objects together into the first object.

    More on my personal blog @www.dotnetjalps.com

    Shout it

  • Static vs Singleton in C# (Difference between Singleton and Static)

    Recently I have came across a question what is the difference between Static and Singleton classes. So I thought it will be a good idea to share blog post about it.

    Difference between Static and Singleton classes:

    1. A singleton classes allowed to create a only single instance or particular class. That instance can be treated as normal object. You can pass that object to a method as parameter or you can call the class method with that Singleton object. While static class can have only static methods and you can not pass static class as parameter.
    2. We can implement the interfaces with the Singleton class while we can not implement the interfaces with static classes.
    3. We can clone the object of Singleton classes we can not clone the object of static classes.
    4. Singleton objects stored on heap while static class stored in stack.

    more at my personal blog: dotnetjalps.com

  • HTML editor enhancement in visual studio 2012

    In this post I am going to explain about HTML Editor Enhancement in visual studio 2012. I have been writing few post about Visual studio 2012 new features and this post will also be part of that. You can read whole series at following link.

    Visual Studio 2012 feature series

    Tag highlighting in Visual Studio 2012:

    In visual studio 2012 You can highlight the start and end tag of a particular HTML element. One you click on starting tag of HTML element it will have other part highlighted just like following.

    HTMLTagHighLightVisualStudio2012

    Automatic Tag Update in Visual studio 2012:

    This feature will help you when you change HTML in Visual studio 2012. When you modify start tag of HTML element it will update end tag automatically. You don’t have to worry about it. For example in above picture we have <div>tag and now if change this to <p> it will automatically update like following.

    AutomaticTagUpdateVisualStudio2012

    Full HTML5 tag support:

    Visual studio 2012 now supports all the HTML5 tag and provide intellisense for that. So You can develop HTML5 web applications very easily.

    Html5SupportVisualStudio2012

    That’s it. Hope you like it. Stay tuned for more..

  • How to hide title bar in jQuery UI modal dialog?

    jQuery UI is a great open source set of user controls and it’s very easy to use. Recently one of my friend asked question that how we can hide title bar in jQuery UI Dialog? so this post is a reply to him. Let’s create a simple html and use jQuery Ui modal dialog. Following is a code for that.

    Here in the above code you can see I have create a hello world pop up with asp.net jQuery CDN.

    <html>
    <head>
        <title>Hello World  Popup</title>
        <link type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.0/themes/smoothness/jquery-ui.css"
            rel="stylesheet" />
        <script language="javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.0.min.js"></script>
        <script language="javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.0/jquery-ui.min.js"></script>
        <script type="text/javascript">
            function Show() {

            $(&quot;#dialog:ui-dialog&quot;).dialog(&quot;destroy&quot;);
    
            $(&quot;#dialog-modal&quot;).dialog({
                height: 300,
                width: 200,
                modal: true
            });
        }
    &lt;/script&gt;
    

    </head> <body> <div id="dialog-modal" title="Hello Word" style="display: none"> Hello World Juqry UI popup </div> <input type="button" onclick="javascript: Show()" value="click me" />

    </body>

    </html>

    Let’s run that in browser. Now you can see if you run this browser it will look like below.

    how to hide title bar in jquery UI modal popup

    Hiding jQuery UI Dialog Title Bar:

    Now If we wnat to  hide dialog box then we just have add one more thing extra in show function in above code to hide Hello Word Title bar with close icon.

    function Show() {
    
        $("#dialog:ui-dialog").dialog("destroy");
    
        $("#dialog-modal").dialog({
            height: 300,
            width: 200,
            modal: true
        });
        $(".ui-dialog-titlebar").hide();
    }

    So in the above code you can see I have written ‘$(".ui-dialog-titlebar").hide();’ .  Now you run that in browser it will look like below.

    how to hide jquery UI dialog box title bar Now hidden  

    That’s it. It’s very easy. Hope you like it. Stay tuned for more..

    Original blog:http://www.dotnetjalps.com/2013/02/How-to-hide-title-bar-in-jQuery-UI-modal-dialog.html

  • How to create overload methods in WCF service with C#

    Before some days I have posted an blog about How to create overloaded web methods in asp.net web service? In this post I am going to explain how we can create overload methods in WCF(Windows Communication Foundation) service with C# language.

    So let’s consider same Hello world example which we have used web service overload method. Let’s create two methods HelloWorld one is with name and another is without parameter. For WCF service we have to first create interface following is a code for that.

    using System.ServiceModel;

    namespace WebApplication4 { [ServiceContract] public interface IHelloWorldOverload { [OperationContract] string HelloWorld();

        [OperationContract]
        string HelloWorld(string name);
    
    }
    

    }

    Now our interface is ready so it’s time to implement this interface and create WCF service like following.

    namespace WebApplication4
    {
        public class HelloWorldOverload : IHelloWorldOverload
        {
            public string HelloWorld() {
                return "Hello World";
            }
    
            public string HelloWorld(string name) {
                return string.Format("Hello World {0}", name);
            }
        }
    }

    So now we are done with WCF service and let’s do compilation so if you compile this It will compile as this is a valid code. Let’s run it in browser. Now the problem will start. You will get following error.

    “Cannot have two operations in the same contract with the same name, methods HelloWorld and HelloWorld in type WebApplication4.IHelloWorldOverload violate this rule. You can change the name of one of the operations by changing the method name or by using the Name property of  OperationContractAttribute.”

    Overload Methods in WCF Service

    Read more

  • SelectMany operator in Linq C#

    SelectMany is an important operator in Linq. It takes each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence. You can find out more information about different overload list from the below link.

    http://msdn.microsoft.com/en-us/library/system.linq.enumerable.selectmany.aspx

    In this post I am going to explain How it can be really useful when you want to find list related to two entities. Practical example will be like a person can have multiple address and if you want to find list of addresses that are used with person and then this SelectMany operator can be really useful.

    So for this example First, I have create Address class with Street and Postalvcode property

    public class Address
    {
        public string Street { get; set; }
        public string PostalCode { get; set; }
    }

    Now we are going to create Person class which have Name property and A person can have multiple address so address generic list as property like following.

    public class Person
    {
        public string Name { get; set; }
        public List<Address> Addresses { get; set; }
    }

    Read more>>

  • Visual studio 2012 color editor- Make Visual studio 2012 Colorful

    This blog will be part of visual studio 2012 features series.

    I personally like the Metro UI for Visual Studio 2102 but  still some people are not happy with it. They really like Old Visual Studio 2010 layout and they wanted to have same kind of color in visual studio 2012. For those who want to change the color of Visual studio there is a plug called Visual Studio 2012 Color Theme editor. From which you can set colors for visual studio UI and make your visual studio look colorful. Following is a link for that.

    http://visualstudiogallery.msdn.microsoft.com/366ad100-0003-4c9a-81a8-337d4e7ace05

    Once you download that from above location and click on installer it will ask for accepting terms and conditions like following.

    Install Visual studio Color editor for visual studio 2012

    Once you select visual studio version and click install it will install the Visual Studio color theme editor. There will be a menu available in Tools->Change Color Theme.

    ThemeMenuVisualStudio2012

    Even you can change color you want via customize color. Once you click that menu it will load the following window to customize color.

    Diffrent color available in visual studio

    Once you write your theme name and click on create button. It will allow you to customize color.

    ColorEditorVisualStudio2012

    Following are different color themes available with Visual Studio 2012 color theme editor.

    read more

  • How to get N row from datatable in C#

    Problem:

    Recently one of my friend was needed only first three rows of data table and so he asked me and I have multiple solutions for that. So thought it would be great idea to share with you guys.

    Possible Solutions to problem:

    There are two ways to solve this problem.

    1. With normal for loop
    2. With lamda expression and linq

    1. With normal for loop:

    Following is code from where we can get 3 rows of data table.

    private  DataTable GetFirst3RowViaFor(DataTable dataTable) {
                DataTable newDataTable = dataTable.Clone();
                for(int i=0;i<3;i++)
                {
                    DataRow row = dataTable.Rows[i];
                    newDataTable.Rows.Add(row);
                }
                return newDataTable;
            }

    Here in this way I have cloned data table structure and then I added first 3 rows of data table to new data table.

    2. With lamda expression:

    Following is a code for that. It’s very easy. I have used lamda expression to get first 3 rows.

    private DataTable GetFirstThreeRowViaLinq(DataTable dataTable) {
                return dataTable.Rows.Cast().Take(3).CopyToDataTable();
            }

    That’s it. Hope you liked it. Stay tuned more updates..

    Original blog post:http://www.dotnetjalps.com/2013/01/how-to-get-n-row-from-datatable-in-csharp.html