Stop auto closing after ipconfig command

January 28, 2010 Amir Aryani Leave a comment

Some minor things can be annoying if you do not know the trick to do it in an easy way. One of them is getting the system IP address using ipconfig, or  executing other Windows commands directly from the Start -> Run. The problem is that the command prompt window will close automatically after execution of the command. So to avoid closing the windows automatically you have two options:

  1. Go to Start -> Run
  2. Type cmd and hit enter.
  3. Type the command (e.g ipconfig) in the opened window.

alternatively you can

  1. Go to Start -> Run
  2. Type cmd /K command and hit enter. (e.g cmd /k ipconfig)

CMD /K will stop the command window from closing after the command.

Categories: IT Support

Microsoft Prism

December 14, 2009 Amir Aryani Leave a comment

I just learned about Prism as a way for developing composite applications using WPF.

Prism as a guideline:

This guidance will help you design and build flexible client applications using loosely coupled, independently evolvable pieces that work together and are integrated into the overall application. This type of application is known as a composite application.

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

To answer the question why using Prism, refer to http://msdn.microsoft.com/en-us/library/dd490815.aspx

Composite applications provide many benefits, including the following:

  • They allow modules to be individually developed, tested, and deployed by different individuals or sub-teams…
  • They provide a common shell composed of UI components contributed from various modules that interact in a loosely coupled way…
  • They promote re-use and a clean separation of concerns between the application’s horizontal capabilities…
  • They help maintain a separation of roles by allowing different individuals or sub-teams to focus on a specific task or piece of functionality according to their focus or expertise…

Other resources:

Categories: Silverlight, WPF

Entity Framework assications (Independent vs FK)

November 8, 2009 Amir Aryani Leave a comment

Entity Framework association is a different concept to FKs in the database schema.  Supporting or not supporting the Schema FKs has been a topic for debate in the community until now. Faisal Mohamood (Program Manager of Entity Framework) believes in the following prons and cons of using FKs in a model (Ref 1):

Benefits of Foreign Keys

  1. Keeps it simple (for the simple cases)  and allows you to deal with relationship like you deal with them in the database
  2. Technically, you can update relationships without having both ends loaded/materialized. This is however in reality not always interesting since you will likely load both ends but this feature is definitely useful.

Disadvantages of Foreign Keys in the Model

  1. It is a part of the impedance mismatch problem.
  2. It doesn’t allow the concepts that you would expect from relationships in objects (easily getting from one end to the other) for instance.
  3. Having foreign keys as well as object references for relationship navigation presents the problem of two different artifacts representing relationships – this introduces complexity and now you have to make sure that you keep these two in sync.

I think the biggest disadvantage of FKs (stated in number 2) is the conflict with the object model pattern.

However, it seems that Microsoft decided that both sides of this discussion have their valid points. So in Entity Framework .Net 4, Fks are supported and it is up to the software architects to make their decision to just use  independent associations (.Net 3.5 SP1) or add the FKs to the model.

The following code snippets form ADO.Net blog illustrate the implication of using Fks as part of the model (Ref 2). In our model there are two entities Product and Category, with the association one to many where each Product belongs to one Category.

First:  Using the independent association between Product and Category.

public void Create_new_Product_in_existing_Category_by_reference()
{
    using (var context = new Context())
    {
        //Create a new product and relate to an existing category
        Product p = new Product
        {
            ID = 1,
            Name = "Bovril",
            Category = context.Categories
                        .Single(c => c.Name == "Food")
        };
        // Note: no need to add the product, because relating
        // to an existing category does that automatically.
        // Also notice the use of the Single() query operator
        // this is new to EF in .NET 4.0 too.
        context.SaveChanges();
    }
}

Second: Using the Foreign Key.

using (var context = new Context())
{
    //Create a product and a relationship to a known category by ID
    Product p = new Product
    {
        ID = 1,
        Name = "Bovril",
        CategoryID = 13
    };
    //Add the product (and create the relationship by FK value)
    context.Products.AddObject(p);
    context.SaveChanges();
}

Further Reading:

References:

  1. [blogs.msdn.com/EFDesign]Foreign Keys in the Conceptual and Object Models
  2. [blogs.msdn.com/EFDesign]Foreign Keys in the Entity Framework
Categories: Entity Framework, LINQ

White space (blank line) top of the ASP.Net Menu in IE8

September 2, 2009 Amir Aryani Leave a comment

Following my previous post about applying a hot fox for ASP.Net menu control, I discovered that the z-index is not the only issue to fix. ASP.Net control when it gets rendered in IE8 shows a gap on top of it like a blank line or a white space.  Sakya found out and explains on his blog that it is the result of SkipLinkText which is not rendered in IE7 but IE8 render it.

The following code snippet shows how to set SkipLinkText to blank.

<asp :Menu ID="Menu1"  runat="server"
     DataSourceID="SiteMapDataSource1"
     SkipLinkText="">
</asp>

For more information refer to http://blogs.iis.net/sakyad/archive/2009/04/11/asp-net-menu-control-getting-padded-with-white-space-on-ie8.aspx.

Categories: ASP.NET Tags: , ,

Align a table in the middle of an HTML | XHTML page

August 26, 2009 Amir Aryani Leave a comment

In the past it was common to align a table in the middle of a HTML page using the following code:

<div align="center">
<table>
<tr>
<td>
        Test String</td>
</tr>
</table>
</div>

However, this is no longer working as in the new XHTML standards “align” is not a valid attribute of

. So a better solution is to set the margin of the table to “auto”. You can delete the
as it is no longer needed for this purpose:

  <table style="margin: auto;">
    <tr>
      <td>
        Test String
      </td>
    </tr>
  </table>
Categories: ASP.NET Tags: , , ,

ASP.Net menu does not work in IE8

August 24, 2009 Amir Aryani 1 comment

The first problem which I found with the ASP.Net applications runing on IE8 was the dynamic menu. It does not invoke correctly as the default value for Z-Index is no longer valid for IE8. The problem and the work around it, is explained in

http://support.microsoft.com/kb/962351

In addition, the following list of issues and hotfixes related to ASP.Net 2 are important to review:

961847 FIX: Error message when you view a page in design mode after you recompile a .NET Framework 3.5 Service Pack 1-based project: “Error creating control – ‘ControlInstanceName [text]‘ could not be set on property ‘PropertyName’”

961864 FIX: Web clients may have several problems when you access an ASP.NET 2.0 AJAX-enabled Web site

961884 FIX: You experience very slow performance on an initial request to an ASP.NET Web site after you change the App_Code folder, the bin folder, or the Global.asax file

962351 FIX: The pop-out menus are not displayed when you use Internet Explorer 8.0 in Standards mode to view an ASP.NET Web page that has dynamic menus

961902 FIX: Error message when you compile an ASP.NET project that contains many application resource files: “A first chance exception of type ‘System.ArgumentException’ occurred in mscorlib.dll”

968392 Error message and the hyperlink control is not rendered if the ImageUrl property is set in Visual Studio 2005 or Visual Studio 2008 after you install .NET Framework 2.0 Service Pack 2 or .NET Framework 3.5 Service Pack 1:”Object reference not set to an instance of an object”

Reference: http://support.microsoft.com/?id=969612

Other blog posts related to this issue: