SubSonic Forums
All Your Database Are Belong To Us

Scaffold Control [BUG]: 1 to 1 Relationship Problem can't edit?

Latest post 05-12-2008 9:12 PM by robsworld2006. 2 replies.
  • 05-12-2008 8:51 AM

    Scaffold Control [BUG]: 1 to 1 Relationship Problem can't edit?

    Hi Guys,

    I've been using the scaffold control and have come across the following problem:

    I have 2 tables setup both contain ProductID as primary key

    ProductionInformation
    ProductID PK
    Description
    Company

    ProductLatestPrices
    ProductID PK FK
    CurrentPrice
    Qty

    Basically I have 2 tables that map 1 to 1 for each other, the reason the tables are split and not in 1 is because I download data to the ProductLatestPrices table.

    When I use the scaffold control I noticed that I end up with the following grid:

    Descrption, Company, CurrentPrice, Qty

    I noticed that there is no ProductID field in the grid? Can this be shown? Why is it hidden?

    The Problem:
    When I click on a row in the grid, in the editor all the textboxes are empty, upon debugging I noticed that in Subsonic\Controls\Scaffold.cs (line 1613), that the primarykeyValue is wrong, instead of getting the productID it gets the description

    protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
            {
                if (grid.DataKeys != null && grid.DataKeys.Count > e.NewEditIndex)
                {
                    DataKey key = grid.DataKeys[e.NewEditIndex];
                    if(key != null)
                    {
                        PrimaryKeyValue = key.Value.ToString(); <---------------------- PROBLEM
                        BuildWithModeChange(ScaffoldMode.Edit);
                    }
                }
            }

    As a result in the code

    Subsonic\Controls\Scaffold.cs (line 706)
    BindEditor(TableSchema, PrimaryKeyValue); <--- the wrong primary key value is being sent so binding to the textboxes has problems 

    As a test I hard coded a primarykey value to see if it would work, and it did therefore I need a way to get this value
    The scaffold works perfect for all my other tables, but not for a 1-1 situation like this, does anyone know what I could try?

    Note:
    I've included a database script containing 2 tables (slighly modified version) but you will see that you can't edit the "ProductExtended" table --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    USE [TestDatabase]
    GO
    /****** Object:  Table [dbo].[Product]    Script Date: 05/13/2008 00:26:51 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[Product](
        [ProductID] [int] IDENTITY(1,1) NOT NULL,
        [Name] [varchar](50) NOT NULL,
     CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED
    (
        [ProductID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object:  Table [dbo].[ProductExtended]    Script Date: 05/13/2008 00:26:52 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[ProductExtended](
        [ProductID] [int] NOT NULL,
        [Price] [real] NOT NULL,
     CONSTRAINT [PK_ProductExtended] PRIMARY KEY CLUSTERED
    (
        [ProductID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    /****** Object:  ForeignKey [FK_ProductExtended_Product]    Script Date: 05/13/2008 00:26:52 ******/
    ALTER TABLE [dbo].[ProductExtended]  WITH CHECK ADD  CONSTRAINT [FK_ProductExtended_Product] FOREIGN KEY([ProductID])
    REFERENCES [dbo].[Product] ([ProductID])
    GO
    ALTER TABLE [dbo].[ProductExtended] CHECK CONSTRAINT [FK_ProductExtended_Product]
    GO


    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Thanks for your time and effort
    Regards DotnetShadow 

     

     

  • 05-12-2008 11:46 AM In reply to

    Re: Scaffold Control [BUG]: 1 to 1 Relationship Problem can't edit?

     Fixed in Revision 440.

    Found a bug? Help us fix it by submitting a Work Item!

  • 05-12-2008 9:12 PM In reply to

    Re: Scaffold Control [BUG]: 1 to 1 Relationship Problem can't edit?

     Thanks, much appreciated keep up the great work

     Regards DotnetShadow

Page 1 of 1 (3 items) | RSS