• Wriju's BLOG

    Windows Live Photo Gallery : Easily Stitch Panoramic Photos

    • 2 Comments

    I am visually challenged nor a good photographer. Recently I have been to the foot hills of Eastern Himalayan range (http://en.wikipedia.org/wiki/Buxa_Tiger_Reserve). I and Tupur been to the dry river bed of Jayanti, took some series of photos. I had plan to stitch them.

    Wonder!!! Live Photo Gallery already has this feature. Bingo!!! I created one.

    Tutorial video is available at MSN Video.

    And the result is,

    JayantiRange

    Namoskar!!!

  • Wriju's BLOG

    www.pinvoke.net a site for use

    • 1 Comments

    http://www.pinvoke.net/default.aspx is a must to have site if you are a frequent user of Windows API and need to create a call for them.

    Namoskar!!!

  • Wriju's BLOG

    What is Cloud Platform

    • 1 Comments

    Read it (why should you waste time on my BLOGJ)

    http://www.davidchappell.com/CloudPlatforms--Chappell.pdf

     

    Namoskar!!!

  • Wriju's BLOG

    CodeRush Xpress an amazing tool to work with Visual Studio 2008

    • 2 Comments

    Today I have came across a tool called CodeRush Xpress, a free AddIn which can be integrated with Visual Studio and make fun of the coding. This is a combined effort which DevExpress have had with Microsoft by leveraging the existing Visual Studio 2008 IDE.

    One scenario is very common to all of us when we need to expose the anonymous type outside the method. Then we need to take the pain of declaring the whole class and use instead of anonymous type. Else there are some type cast way of doing it.

    CodeRush made this easy for us, and now we can create class out of any anonymous type per say.

    Let’s say you have the line,

    var obj = new { Id = 1, Name = "Wriju" };

    Install CodeRush and  put your cursor at “new”, click Ctrl+~ (tilde button above Tab). This will create a whole class for you like,

    [DebuggerDisplay("\\{ Id = {Id}, Name = {Name} \\}")]

    private sealed class MyClass : IEquatable<MyClass>

    {

        private readonly int _Id;

        private readonly string _Name;

     

        public MyClass(int id, string name)

        {

            _Id = id;

            _Name = name;

        }

     

        public override bool Equals(object obj)

        {

            if (obj is MyClass)

                return Equals((MyClass)obj);

            return false;

        }

        public bool Equals(MyClass obj)

        {

            if (!EqualityComparer<int>.Default.Equals(_Id, obj._Id))

                return false;

            if (!EqualityComparer<string>.Default.Equals(_Name, obj._Name))

                return false;

            return true;

        }

        public override int GetHashCode()

        {

            int hash = 0;

            hash ^= EqualityComparer<int>.Default.GetHashCode(_Id);

            hash ^= EqualityComparer<string>.Default.GetHashCode(_Name);

            return hash;

        }

        public override string ToString()

        {

            return String.Format("{{ Id = {0}, Name = {1} }}", _Id, _Name);

        }

     

        public int Id

        {

            get

            {

                return _Id;

            }

        }

        public string Name

        {

            get

            {

                return _Name;

            }

        }

    }

    There are many more and I will let them published in my blog. But this is a great tool for developers who live their life with VS source code.

    Namoskar!!!

  • Wriju's BLOG

    Visual Studio 2010: First Look of my VS 2010

    • 3 Comments

    How this new Visual Studio 2010 looks like? This has three views. Here it is,

    Start Page > Welcome

    image

    Start Page > Projects

    image

    Start Page > Visual Studio

    image

    Namoskar!!!

  • Wriju's BLOG

    C# 4.0: My First Dynamic Program

    • 2 Comments

    I am super excited to see Anders demonstrating C# 4.0 for first time in public. I am a real fan of him and downloaded the public bit to tryout. Here is my first Dynamic C# 4.0 program.

     

    There is nothing much to be excited from my Program but I am very much after hitting F5.

     

    static void Main(string[] args)

    {

        dynamic i = 10;

        dynamic sHello = "Hello C# 4.0";

     

        Console.WriteLine(i);

        Console.WriteLine(sHello);

    }

     

    More to come.

     

    Namoskar!!!

  • Wriju's BLOG

    PDC 2008 Must be Enjoyed

    • 1 Comments

    If you are thinking that you are a looser not by attending PDC 2008, forget it. Stretch your body as you might to stay connected to your chair for long time.

    What is

    • Visual Studio 2010
    • Windows Azure
    • Project "Velocity"
    • Dublin
    • Oslo
    • Parallelism
    • S+S

    and many more.. So without wasting time join and view the video, download them.

    https://sessions.microsoftpdc.com/

    https://sessions.microsoftpdc.com/public/timeline.aspx

    image

    Namoskar!!!

  • Wriju's BLOG

    Application Architecture Guide 2.0 EBook

    • 4 Comments

    For you to design the better future.

    image

    Link to download http://www.codeplex.com/AppArchGuide 

    Namoskar!!!

  • Wriju's BLOG

    ADO.NET Entity: LINQ to Entity with Relationship

    • 4 Comments

    Relationship and getting data from Entity Framework using Northwind database

    image

    Simple Query

     

    using (NorthwindEntities ctx = new NorthwindEntities())

    {

        var query = from o in ctx.Orders

                    select o.OrderID;

     

        foreach (var k in query)

        {

            Console.WriteLine(k);

        }

    }

     

    Now if you want to filter this with the parent information,

     

    var query = from o in ctx.Orders

                where o.Customers.City == "London"

                select o.OrderID;

    This actually goes one level up and then filters the data.

     

    Include Child Information

     

    var query = from c in ctx.Customers

                where c.City == "London"

                select c;

     

    foreach (var k in query)

    {

    Console.WriteLine(k.ContactName);

    }

     

    Now if you want to get the “Orders” table, there are two ways to do it,

     

    Immediate Loading

     

    var query = from c in ctx.Customers.Include("Orders")

                where c.City == "London"

                select c;

     

    foreach (var k in query)

    {

        Console.WriteLine(k.Orders.Count);

    }

     

    On-Demand Loading

     

    var query = from c in ctx.Customers

                where c.City == "London"

                select c;

     

    foreach (var k in query)

    {

        //if not loaded then load it

        if (!k.Orders.IsLoaded)

            k.Orders.Load();

     

        Console.WriteLine(k.Orders.Count);

    }

     

     

    Namoskar!!!

     

  • Wriju's BLOG

    MSDN Magazine Online

    • 1 Comments

    Get your MSDN magazine from web at http://msdn.microsoft.com/msdnmag/.

    Namoskar!!!

  • Wriju's BLOG

    ADO.NET Entity: Insert Update and Delete with Relationship

    • 18 Comments

    Few days back I had written an article on Insert/Update/Delete for simple standalone tables at ADO.NET Entity: Insert Update and Delete. Now after that many of you had requested me to put article on how it works with relationship.

     

    Here I will use a database created by me. There will be two tables connected with each other.

    image

    Now I will create TestDB.edmx out of this database.

     

    image 

    Insert

     

    using (TestDBEntities ctx = new TestDBEntities())

    {

        //Create new Department

        Dept d = new Dept() { DeptName = "ADO Entity" };

     

        //Create new Employee 1

        EmpDept ed1 = new EmpDept() { EmpName = "ADO Employee 1" };

     

        //Create new Employee 2

        EmpDept ed2 = new EmpDept() { EmpName = "ADO Employee 2" };

     

        //Add employee to the Dept *OBJECT*

        d.EmpDept.Add(ed1);

        d.EmpDept.Add(ed2);

     

        //Updating the context

        ctx.AddToDept(d);

     

        //Save to Database

        ctx.SaveChanges();

    }

     

    Update

     

    using (TestDBEntities ctx = new TestDBEntities())

    {

        //Get an existing Department

        Dept dep = (from d in ctx.Dept

                    where d.DeptId == 22

                    select d).First();

     

        //Set new Department name

        dep.DeptName = "ADO.NET 3.0";

     

        //Create new Employee 2

        EmpDept ed2 = new EmpDept() { EmpName = "ADO 2" };

     

        //Add *new* employee to the Dept *OBJECT*

        dep.EmpDept.Add(ed2);

     

        //Save to Database

        ctx.SaveChanges();

    }

     

    Delete

     

    using (TestDBEntities ctx = new TestDBEntities())

    {

        //Get an existing Department

        Dept dep = (from d in ctx.Dept.Include("EmpDept")

                    where d.DeptId == 22

                    select d).First();

     

        /*

         Needd to do ToList() becuase once you delete

         a record then iteration will not be possible.         

        */

        foreach (EmpDept ed in dep.EmpDept.ToList())

        {

            //This removes relationship from Context

            dep.EmpDept.Remove(ed);

     

            //Delete it from context

            ctx.DeleteObject(ed);       

        }

     

        //Delete the master table

        ctx.DeleteObject(dep);

           

        //Save to Database

        ctx.SaveChanges();

    }

     

    Note: during delete you first need to remove the relationship from entity and then delete the object from entity. So you need to keep the child data offline and then do operation. Then delete the main object.

     

    In my next post I will write about “how to select with Relationship”.

     

    Namoskar!!!

     

  • Wriju's BLOG

    Visual Studio 2010 and .NET Framework 4.0 Overview

    • 0 Comments

    Know more about it and keep you sink with http://msdn.microsoft.com/en-us/vstudio/products/cc948977.aspx

    What's New

    Additional Resources

    Namoskar!!!

  • Wriju's BLOG

    ADO.NET Entity: Insert Update and Delete

    • 28 Comments

    For small blogs, it requires more references and explanation, which sometimes are redundant. So I thought of writing single blog which is combination of topics more or less related to one thing.

     

    I am exploring ADO.NET Entity Framework and have been trying things out there. Here I am planning to demonstrate how to do insert, update and delete.

     

    Here I will use a database created by me. In the Emp table there are two columns Id (Primary and auto-generated) and Name (simple varchar(50)).

    image

    Now I will create TestDB.edmx out of this database.

    image

    Insert

     

    using (TestDBEntities ctx = new TestDBEntities())

    {

        //Create new Emp object

        Emp e = new Emp() { Name = "Test Employee" };

     

        //Add to memory

        ctx.AddToEmp(e);

     

        //Save to database

        ctx.SaveChanges();

    }

     

     

    Update

     

    using (TestDBEntities ctx = new TestDBEntities())

    {

        //Get the specific employee from Database

        Emp e = (from e1 in ctx.Emp

                 where e1.Name == "Test Employee"

                 select e1).First();

     

        //Change the Employee Name in memory

        e.Name = "Changed Name";

     

        //Save to database

        ctx.SaveChanges();

    }

     

    Delete

     

    using (TestDBEntities ctx = new TestDBEntities())

    {

        //Get the specific employee from Database

        Emp e = (from e1 in ctx.Emp

                 where e1.Name == "Test Employee"

                 select e1).First();

     

        //Delete it from memory

        ctx.DeleteObject(e);

     

        //Save to database

        ctx.SaveChanges();

    }

     

    In my next post I will write about “how to handle CRUD with Relationship”.

    Namoskar!!!

  • Wriju's BLOG

    Microsoft Project Code Named “Velocity”

    • 1 Comments

    "Velocity" is a distributed in-memory application cache platform for developing scalable, high-performance applications. "Velocity" can be used to cache any CLR object and provides access through simple APIs. The primary goals for "Velocity" are performance, scalability and availability.

    http://msdn.microsoft.com/en-us/data/cc655792.aspx

    Technical Articles

    Blog

    Microsoft Project Code Named "Velocity" Team Blog

    Forum

    Microsoft Project Code Named “Velocity”

    Download

    Microsoft Project Code Named “Velocity”

    Samples

    Microsoft Project Code Named “Velocity” on Code Gallery

    Namoskar!!!

  • Wriju's BLOG

    Windows Forms – Enable Shortcut Key all over the Form

    • 10 Comments

    Windows Application and shortcut key are synonyms. People prefer to use shortcut keys for faster activity. Assume you are in a text box and you want to hit F5 to reload the form. You do not want to move your mouse cursor. So what you will be doing is that you will be adding “Key Down” event to the text box. But if you are in a different text box or in a button that will not work. So you will add “Key Down” event to your form.

     

    But you need to enable a property to work it properly and that’s the trick.

     

    private void Form1_KeyDown(object sender, KeyEventArgs e)

    {

        if (e.KeyCode == Keys.F5)

        {

            btnRefresh_Click(null, null);

        }

    }

     

    But golden trick is, in the property window of the Form make the following changes

     

    KeyPreview = True 

    Enjoy programming. 

    Namoskar!!!

  • Wriju's BLOG

    Programmatically invoking the Live.com search

    • 0 Comments

    Live.com you need to automate that in your Windows application. You will use the WebBrowser control. This is a very powerful control and allows us to control things through DOM. Here is a small code which insert values to the live.com’s seach text box and clicks the “Go” button. I have created a windows forms application and added a WebBrowser control named “webBrowser1”.

     

    //Set the value to the Search text box

    webBrowser1.Document.GetElementById("sb_form_q").SetAttribute("value", "Wriju's BLOG");

     

    //Now click the button

    //this actually submits the one and only one form

    //So you need to do that

    webBrowser1.Document.Forms[0].InvokeMember("submit");

     

    Namoskar!!!

  • Wriju's BLOG

    LINQ to SQL vs. ADO.NET – A Comparison

    • 17 Comments

    ADO.NET is our contemporary data access component and now we have written many applications. Now there has been a lot of talk on LINQ to SQL. So we are little skeptical about this component and trying to find some relation between existing ADO.NET technology.

     

    Purpose of this post is to give some quick brief on some major differences between ADO.Net and LINQ to SQL. I have not used 100% code as this is just to give an idea. The database I have used here is Northwind (SQL Server 2000 Sample database).

     

    Some comparison,

     

    Scenario 1

    +++++++

    Establishing connection between database and application,

     

    ADO.NET

    using(SqlConnection conn = new SqlConnection("Connection String"))

    {

        conn.Open();

    }

     

    LINQ to SQL

    You create a .dbml file and give a name (assume “NW.dml”). Then there will be a DataContext class created. So you need to initialize the instance of an object.

     

    NWDataContext db = new NWDataContext("Connection String");

     

    You do not need to call any Open() method. Datacontext handles well the open and close method.

     

    Scenario 2

    +++++++

    Getting data from database,

     

    ADO.NET

    using(SqlConnection conn = new SqlConnection("Connection String"))

    {

        using (SqlCommand comm = new SqlCommand("Select * from Customers"))

        {

            conn.Open();

            SqlDataReader reader = comm.ExecuteReader();

            DataTable dt = new DataTable("New Table");

            dt.Load(reader);

        }

    }

     

    LINQ to SQL

    using (NorthwindDataContext db = new NorthwindDataContext())

    {

        //You can also use "var" at "IEnumerable<Customer>"

        IEnumerable<Customer> custs = from c in db.Customers

                                      select c;

     

        foreach (Customer c in custs)

        {

            Console.WriteLine(c.CompanyName);

        }

    }

     

    WOW!!! I have received comment from our Senior Program Manager Dinesh Kulkarni from LINQ to SQL team when I requested him to visit my blog. He mentioned,

    DataTable provides you a cache that can be re-enumerated without DB roundtrip while LINQ to SQL results need to be explicitly cached with something like a ToList()/ToArray(). Identity caching in DataContext aside, the L2S code is closer to enumerating a DataReader. Although DataReader does not allow you to re-enumerate and requires another ExecuteReader, the impact of reenumerating L2S query is the same – another roundtrip to DB.

    Scenario 3

    +++++++

    Inserting into the database,

     

    ADO.NET

     

    using(SqlConnection conn = new SqlConnection())

    {

        conn.Open();  

        SqlCommand comm = new SqlCommand("INSERT INTO...", conn);

     

        comm.ExecuteNonQuery();

    }

     

    LINQ to SQL

     

    using (NorthwindDataContext db = new NorthwindDataContext())

    {

        //Create a new object

        Customer c = new Customer();

        c.CustomerID = "ABCDE";

        //.... add all the properties you need to add while inserting

     

        //Add it to the collection

        db.Customers.InsertOnSubmit(c);

     

        //Save the changes to the database

        db.SubmitChanges();   

    }

     

    Scenario 4

    +++++++

    Updating database,

    ADO.NET

     

    Same as Scenario 3

     

    LINQ to SQL

    using (NorthwindDataContext db = new NorthwindDataContext())

    {

        //Get the object from database

        Customer cust = (from c in db.Customers where c.CustomerID == "ALFKI" select c).First();

     

        //Update the exsisting value

        cust.CompanyName = "I do not know?";   

       

           

        //Save the changes to the database

        db.SubmitChanges();   

    }

     

    Scenario 5

    +++++++

    Deleting records from the database,

    ADO.NET

     

    Same as Scenario 3

     

    LINQ to SQL

    using (NorthwindDataContext db = new NorthwindDataContext())

    {

        //Get the object from database

        Customer cust = (from c in db.Customers where c.CustomerID == "ALFKI" select c).First();

     

        //Remove it from collection

        db.Customers.DeleteOnSubmit(cust);

           

        //Save the changes to the database

        db.SubmitChanges();   

    }

     

    Scenario 5

    +++++++

    Executing stored proc which returns record(s),

     

    ADO.NET

    using(SqlConnection conn = new SqlConnection())

    {

        conn.Open();

        using (SqlCommand comm = new SqlCommand("SalesByCategory", conn))

        {

            comm.CommandType = CommandType.StoredProcedure;

            comm.Parameters.AddWithValue("@param1", "value1");

            comm.Parameters.AddWithValue("@param2", "value2");

     

            SqlDataReader reader = comm.ExecuteReader();       

        }

    }

     

    LINQ to SQL

    In LINQ to SQL it becomes metod as you drag and drop it to .dbml file,

     

    using (NorthwindDataContext db = new NorthwindDataContext())

    {

     

        var outPut = db.SalesByCategory("SeaFood", "1998");        

    }

     

    Performance of LINQ to SQL and ADO.NET

     

    LINQ to SQL Performance Part 1

    LINQ to SQL Performance Part 2

    LINQ to SQL Performance Part 3

    LINQ to SQL Performance Part 4

    LINQ to SQL Performance Part 5

     

    There are a many to discuss. Hope you have enjoyed it.

     

     

    Namoskar!!!

  • Wriju's BLOG

    Celebrating 200th MSDN Blog Post

    • 0 Comments

    Wow experience!!! 200+ posts on MSDN with millions of hits it’s a great pleasure being at Microsoft with additional takeaways. I never thought in my life that I would be blogging. I had a dream that one day I will become writer (was not sure on what though). Blogging is a great tool to give values back to community for people with less power (like me or introvert).

    My journey has been always a pleasure (be it blogging or 5 day long on-road cross country cargo truck travel). But my greatest takeaway was when my blog was in MSDN C# Home page. Charlie was kind enough to put my blog in the same list with Scott Guthrie (http://weblogs.asp.net/scottgu/). I never had a clue on how Scott manages to write blog so regularly.

    You may find some of my selected and relevant past posts are at Charlie’s blog at Community Convergence and my journey stared from Community Convergence XXXV. I have no words to say thanks to Charlie (our very own C# Community Program Manager).  Many people have encouraged me in many ways, Program managers, friends, Microsoft Partners (with whom I work professionally), my super technical Microsoft teammates, people from everywhere over the web. Some of them have added my blog to their favorite list (priceless to me always).

    There are many things I have planned to write. I am a lazy person, so I need to be focused and keep on contributing to my blog.

    But I have promises to keep,

    And miles to go before I sleep,

    And miles to go before I sleep.

     

    I am not a good writer, but I love many things at Microsoft.

     

    Namoskar!!!

  • Wriju's BLOG

    How to copy my snippet in Visual Studio 2008

    • 2 Comments

    I use Visual Studio 2008 code snippet a lot when I write code for my presentation. It saves a lot of time and it is very elegant. But I used to struggle a lot while changing my demo machine. Because I had to repeat the same process again and again from Tools > Snippet Manager, I find it very inconvenient if you have many snippets.

    There is an elegant way to do that, under

    C:\Documents and Settings\<<logged in user>>\My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets  

    Copy the files from your source machine and paste them to the destination machine’s same folder. You will get all the snippets. You do not have to use Snippet Manager anymore to upload snippet.

    Namoskar!!!

  • Wriju's BLOG

    ZoomIt : Fantastic Windows Zooming Application

    • 1 Comments

    When I show demo using my desktop I often come across to the scenarios where things are very small. I was using Windows Magnifier. I found this tool later and this is very helpful. This tool was created by Microsoft Technical Fellow, Mark Russinovich.

    Some facts,

    Ø  ZoomIt runs on System Tray

    Ø  Allows you to use configurable shortcut key

    This is very lightweight and simple tool. You will enjoy if you use them.

    http://technet.microsoft.com/en-us/sysinternals/bb897434.aspx

    Namoskar!!!

  • Wriju's BLOG

    Visual Studio 2008 : How to zoom Class Diagram

    • 3 Comments

    During my demos I have noticed that Class Diagram in Visual Studio gives a very detailed view with lot of information. Now this is hard for people sitting at the back of the room to see what is there.

    It’s very easy, if you press “CTRL” then scroll the mouse, this will zoom in and out the class diagram.

    Namoskar!!!

  • Wriju's BLOG

    LINQ to SQL : Missing Manual are at MSDN

    • 1 Comments

    ADO.NET and LINQ to SQL

    Describes the relationship of ADO.NET and LINQ to SQL.

     

    Analyzing LINQ to SQL Source Code

    Describes how to analyze LINQ to SQL mapping by generating and viewing source code from the Northwind sample database.

     

    Customizing Insert, Update, and Delete Operations (LINQ to SQL)

    Describes how to add validation code and other customizations.

     

    Data Binding (LINQ to SQL)

    Describes how LINQ to SQL uses IListSource to support data binding.

     

    Inheritance Support (LINQ to SQL)

    Describes the role of inheritance in the LINQ to SQL object model, and how to use related operators in your queries.

     

    Local Method Calls (LINQ to SQL)

    Describes LINQ to SQL support for local method calls.

     

    Data Retrieval and CUD Operations in N-Tier Applications (LINQ to SQL)

    Provides detailed information for multi-tier applications that use LINQ to SQL.

     

    Object Identity (LINQ to SQL)

    Describes object identity in the LINQ to SQL object model, and explains how this feature differs from object identity in a database.

     

    The LINQ to SQL Object Model

    Describes the object model and its relationship to the relational data model.

     

    Object States and Change-Tracking (LINQ to SQL)

    Provides detailed information about how LINQ to SQL tracks changes.

     

    Optimistic Concurrency Overview (LINQ to SQL)

    Describes optimistic concurrency and defines terms.

     

    Query Concepts in LINQ to SQL

    Describes aspects of queries in LINQ to SQL that differ from queries in LINQ.

     

    Security in LINQ to SQL

    Describes the correct approach to security in database connections.

     

    Serialization (LINQ to SQL)

    Describes the serialization process in LINQ to SQL applications.

     

    Stored Procedures (LINQ to SQL)

    Describes how to map stored procedures at design time and how to call them from your application.

     

    Transactions (LINQ to SQL)

    Outlines the three models of transaction that LINQ to SQL supports.

     

    Type System Mismatches (LINQ to SQL)

    Describes the challenges of mingling different type systems.

     

    User-Defined Functions (LINQ to SQL)

    Describes how to map user-defined functions at design time and how to call them from your application.

     

    Namoskar!!!

     

  • Wriju's BLOG

    LINQ to SQL : Troubleshooting

    • 1 Comments

    Problem with LINQ to SQL? Want to troubleshoot?

    http://msdn.microsoft.com/en-us/library/bb386996.aspx

    Namoskar!!!

  • Wriju's BLOG

    LINQ to SQL FAQ

    • 1 Comments

    List of FAQs are at MSDN http://msdn.microsoft.com/en-us/library/bb386929.aspx

    Namoskar!!!

  • Wriju's BLOG

    What do I have to do if I install IIS after Visual Studio

    • 8 Comments

    What happens if you install you Visual Studio then realize that you need IIS for you application to test and run. We often do this. I have seen people uninstalling Visual Studio and then installing it again after IIS to make sure ASP.NET works fine.

    Wow!! There is an easy way to do it,

    Open the command prompt for Visual Studio 2008. Run the following command

    aspnet_regiis –i

    -i  

    Install this version of ASP.NET and update scriptmaps at  the IIS metabase root and for all scriptmaps below the root. Existing scriptmaps of lower version are upgraded to

    this version. (this is from product documentation help text)

     

    You can also check if the specific ASP.Net version is already attached with IIS by using –lv.

     

    Namoskar!!!

     

Page 17 of 25 (618 items) «1516171819»