locked
lightswitch cannot get entities in first query RRS feed

  • Question

  • hello:I am confuse by this problem several days,I cannot get the related entities by the first time.the table relation is below.

    the 'Researchment' has two 0,1 to many collections, 'EmployeeNumberCollection' and 'ResearchAttachmentCollection', when I try to get 'EmployeeNumberCollection',
    and 'ResearchAttachmentCollection' by "var empItem = resItem.EmployeeNumberCollection.array[k];" I can not get empItem at the first query,
    but I can get it in the second query,why this happened?

    function OrganizeByYear(entityCollection) {
        var attachHashSet = [];
        for (var i = 0; i < entityCollection.count; ++i) {
            screen.ResearchmentQuery.selectedItem = resItem;
            var resItem = entityCollection.data[i];
    
            if (resItem.ResearchAttachmentCollection) {
                for (var j = 0; j < resItem.ResearchAttachmentCollection.array.length; ++j) {
                    var attItem = resItem.ResearchAttachmentCollection.array[j];
                    attachHashSet[attItem.Year] = attItem;
                }
            }
            
            if (resItem.EmployeeNumberCollection) {
                for (var k = 0 ; k < resItem.EmployeeNumberCollection.array.length; ++k) {
                    var empItem = resItem.EmployeeNumberCollection.array[k];
    
                    var value = {};
                    PushResearchBaseData(value, resItem);
    
                    //combine the data in EmployeeNumberCollection and EmployeeNumberCollection with same year value
                    var attItem = attachHashSet[empItem.Year];
                    if (attItem) {
                        PushResAttachData(value, attItem);
                        PushResEmpData(value, empItem, true);
                        delete attachHashSet[empItem.Year];
                    } else {
                        PushResEmpData(value, empItem, false);
                    }
                    _researchmentData_main.push(value);
                }
            }
            //add the rest data that doesn't contains same year
            attachHashSet.forEach(function (item) {
                var value = {};
                PushResearchBaseData(value, resItem);
    
                PushResAttachData(value, item);
    
                _researchmentData_main.push(value);
            })
        }
    }


    Monday, November 3, 2014 8:54 AM

Answers

  • If you want to modify a query in ways that go beyond the capabilities of the query designer, you can extend the query by writing code.

    Visual Studio LightSwitch combines the conditions that you specify in the query designer with the conditions that you specify in your code to produce the query result. For more information, see Queries: Retrieving Information from a Data Source.

    Software Engineer | mark as answer if it helped

    • Marked as answer by Angie Xu Monday, November 10, 2014 6:51 AM
    Tuesday, November 4, 2014 8:35 AM

All replies

  • If you want to modify a query in ways that go beyond the capabilities of the query designer, you can extend the query by writing code.

    Visual Studio LightSwitch combines the conditions that you specify in the query designer with the conditions that you specify in your code to produce the query result. For more information, see Queries: Retrieving Information from a Data Source.

    Software Engineer | mark as answer if it helped

    • Marked as answer by Angie Xu Monday, November 10, 2014 6:51 AM
    Tuesday, November 4, 2014 8:35 AM
  • thanks
    Tuesday, November 4, 2014 1:25 PM