locked
Nested collection (A) within a nested collection (B) of (C) databind incorrectly on auto generated ListDetailView RRS feed

  • Question

  • I have a simple project with 3 tables. My competitor table have some products and these products have many different prices as they quote various prices to various customers.<o:p></o:p>

    The relationship looks as follows (VS solution included) "Competitor (has many) Products (has many) Prices" <o:p></o:p>

    However, when I auto create CompetitorListDetail form from my Competitors data that shows both Product and Price collections I have an errors when adding various prices to a product. It appears that new Price added "binds" to all Products and not just to the product that I added it to. Now click on the next Product and it disappears.

    Tuesday, November 18, 2014 1:06 PM

Answers

  •   // Child RowsLayout
    
        ContentItem ChildRowsLayoutItem = host.AddContentItem(ParentRowsLayoutItem,
    
            "ChildRowsLayout", ContentItemKind.Group);
    
        ChildRowsLayoutItem.View = "Microsoft.LightSwitch.MobileWeb:RowsLayout";
    
    
        // Add the Custom Control to display the nested collection                
    
        IEntityPropertyDefinition IdProperty =
    
            collectionDataType.Properties.Where(p => p.Name.ToLower() == "id").FirstOrDefault();
    
    
        // Entity of Primary data source must have a Id property to proceed
    
        if (IdProperty != null)
    
        {
    
            // Expression used to access Id property of the element in the Primary data source
    
            ChainExpression nameExpression =
    
                host.CreateChainExpression(
    
                host.CreateMemberExpression(String.Format(@"{0}/Properties[Id]", collectionDataType.Name))
    
                );
    
    
            // Add the CustomControl 
    
            ContentItem namePropertyControl = host.AddContentItem(ChildRowsLayoutItem,
    
                                                                            "NestedElements",
    
                                                                            ContentItemKind.Value,
    
                                                                            nameExpression,
    
                                                                            IdProperty.PropertyType);
    
    
            namePropertyControl.View = "Microsoft.LightSwitch.MobileWeb:ValueCustomControl";
    
        }
    


    Here is article about Adding the Custom Control to display the nested collection     

    http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/3246/Creating-Advanced-LightSwitch-HTML-Screen-Templates.aspx         

    • Marked as answer by Angie Xu Friday, November 28, 2014 5:23 AM
    Thursday, November 20, 2014 2:23 AM