Archive

Author Archive

Entity Framework assications (Independent vs FK)

November 8, 2009 amiraryani 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 amiraryani 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: , ,

Make the ASP:Login control centre

August 26, 2009 amiraryani Leave a comment

Following my previous post you cannot use “p” or “div” tags to align a ASP:Login control to the center of the page. So to get this done, you need to set the margin property of the control to “auto”.

<body>
    <form id="form1" runat="server">
<div>
        <asp :login runat="server" Style="margin:auto"></asp></div>
</form>
</body>

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

August 26, 2009 amiraryani 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 amiraryani 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:

Visual Studio Setup (deployment) project

August 7, 2009 amiraryani 1 comment

Reading the Microsoft support article about using the Setup project in Visual Studio:

In order to create a Setup deployment project :

  1. Start a new project by doing one of the following:
    • On the File menu, point to New, and then click Project.

      -or-

    • If you have an project open that you would like to create a setup package for, right-click Solution MyProject (where the name of your project is MyProject) in the Solution Explorer, point to Add, and then click New Project.
  2. In the New Project dialog box, select Setup and Deployment Projects in the Project Type pane, and then select the type of setup that you want in the Templates pane.

    The project is added to the Solution Explorer, and then the File System Editor opens.

  3. In the Properties dialog box, select the ProductName property, and then type the name of your product.

And to add files to the Setup project:

  1. In the File System Editor, select the Application Folder node.
  2. Right-click the Application folder, and then on the Action menu, click Add, File. In the Add Files dialog box, browse to select any files that you need to add to your application.

    NOTE: If you already have an application project in your solution, you can add the project outputs by selecting Project Outputs instead of File.

  3. To add an existing merge module to your setup package (this is not possible for a Cab project), right-click the name of your setup package in the Solution Explorer. Click Add, and then click Merge Module. In the Add Modules dialog box, browse to select any merge modules that you need to add to your application.

To create a shortcut for the installed program:

  1. Open the File System Editor: from the View menu, point to Editor, and then click File System.
  2. Open the application folder that contains the file that you want to create a shortcut for.
  3. Right-click the file that you want to create a shortcut to.
  4. Click Create Shortcut.
  5. A shortcut will be created in the same folder as the original file.
  6. Drag the shortcut to the desired folder. For example, if you want to create a shortcut in your Program menu, drag the shortcut to the Programs menu folder; if you want to create a shortcut on the Start menu, drag the shortcut to the Start menu folder. The folder location of the shortcut can also be changed through the folder field of the Properties Window.

To register COM objects as part of the installation:

  • Add a COM object to your Visual Studio deployment project.
  • In the Solution Explorer, right-click the module that you just added, and then click Properties.

    NOTE: The Properties window contains a table with two columns and x number of rows (the number of rows depends on the project). The left column lists the specific properties. The right column is explained in step 4.

  • Go to Properties for this module (located by default in the upper-right corner of the .NET Deployment project), and then click Registry property.

    NOTE: The Registry property specifies whether a file, assembly, or project output group should be registered on a target computer during installation.

  • There is a list box in the right column of the Registry property, which displays several options for you to choose from. Note the following details for an explanation of these options:
    • For assembly, registration is not normally required, and therefore the default is DoNotRegister (this means that the item will not be registered during the installation).
    • For a COM module, you have the options of COM, COMRelativePath, and COMSelfReg. Any one of those three options will register the COM module during the installation.

      Note the following details about each choice:

    • COM: The module will be registered as a COM object by the Windows Installer engine. The deployment project will update the Class table, ProgID table, and other tables in the Registry Tables group of the corresponding .msi file. This is the recommended way to register a COM module.
    • COMRelativePath: The module will be registered as an isolated COM object by the Windows Installer engine. Note that this module will be used only by the application that the module is installed with.
    • COMSelfReg: The installer calls the DllRegisterServer function of that module at the time that you install the module and the DllUnregisterServer function at the time that you uninstall the module. The deployment project will update the SelfReg table of the corresponding .msi file. It is not recommended that the installation package use self-registration. Instead, the installation package should register modules by authoring one or more of the other tables provided by the installer for this purpose (that is, select the COM or COMRelativePath options). Many of the benefits of having a central installer service are lost with self-registration, because self-registration routines tend to hide critical configuration information.

    Referemces:

    1. http://support.microsoft.com/kb/307353
    2. http://support.microsoft.com/kb/307358
    3. http://support.microsoft.com/kb/307367

    States pane not visible in Blend 3

    August 2, 2009 amiraryani Leave a comment

    When I started to follow some of the video tuturial for Expression Blend 3, I noticed that States pane is not available when I work on the WPF project; however, it is there when I create a Silverlight project. Apparetly the state manager is part of WPFToolkit and the work arround this issue is explained in  team blog of the Expression Blend:

    Here are the steps you need to follow to get to the VSM-for-WPF goodness:

    1. Install the WPF Toolkit from http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=15598
    2. Create the following registry value and make it non-zero. The value should be of type DWORD. Or run the appropriate .REG file attached to this post (or by clicking here).
    3. 32 bit OS : HKLM/Software/Microsoft/Expression/Blend/EnableVSM
    4. 64 bit OS : HKLM/Software/Wow6432Node/Microsoft/Expression/Blend/EnableVSM
    5. If Blend was running during the previous step then restart it.
    6. Create a new WPF project.
    7. Add %Program Files%\WPF\WPF Toolkit\…\WPFToolkit.dll to the References folder (Right-click the References node in Project, then click Add Reference…).
    8. Close and reopen Window1.xaml. The States pane will now appear for the project.

    Reference: http://blogs.msdn.com/expression/archive/2008/10/30/blend-2-sp1-wpf-toolkit-visual-state-manager-for-wpf.aspx