Search code examples
c#visual-studio-lightswitch

Extract results in code Lightswitch query


I am new to C# and Lightswitch so my explanations may be somewhat convoluted, my apologies in advance. I have a functional query (in code) that uses the _SingleorDefault method and returns a != null value. In debug mode i can expand the 'Results View will enumerate the IEnumerable' and see the record that is returned along with the rest of the EntitySet. How do i reference members of this set within the code? This query does not return results to the screen so a Visual Collection methods return null values. Here's the query.

IDataServiceQueryable<DUTFullView> query;
        query = from DUTFullViewIDpass in this.DataWorkspace.AUTOData.DUTFullViews
                where (DUTFullViewIDpass.DUTTypeID == v.DUTTypeID)
                && (DUTFullViewIDpass.SN == v.SN)
                select DUTFullViewIDpass;

        if (query.SingleOrDefault() != null)

Watch Window view

Response to proposed solution


Solution

  • You should iterate through with foreach

    IDataServiceQueryable<DUTFullView> query = (from DUTFullViewIDpass in this.DataWorkspace.AUTOData.DUTFullViews
                    where (DUTFullViewIDpass.DUTTypeID == v.DUTTypeID)
                    && (DUTFullViewIDpass.SN == v.SN)
                    select DUTFullViewIDpass).Take(1);
    
    if(!query.Any())
        return;
    
    foreach(var item in query)
    {
        // You could do your logic here
        //var example = item.Property1
    }