locked
Execute Linq query in Changed event RRS feed

  • Question

  • LS 2012. I have a Create New Person screen. The screen contains a number of text controls that are calculated at runtime. The user enters a "Number of Days" into a text box and in the Changed event I will run the calculations to fill out several other fields 

    One of these calculations involves a lookup on another entity thats not part of the screen or query at the moment. Does anyone have an example of executing a linq query against an entity in this manner? I want to pass an id and current date to the query and retrieve one row of data which will help me in the calculation process above. 

    Thanks in advance ! 

    Thursday, December 13, 2012 8:43 PM

Answers

  • In VB you might use something like this.

    Dim q = From x In Me.DataWorkSpace.MyDataSource.MyEntity

    Where (x.MyProperty.Id = Me.MyProperty.Id) AndAlso (x.Date = System.Date.Today)

    Select x

    Dim r = q.SingleOrDefault

    If (r IsNot Nothing) Then

    'Your calculation here.

    EndIf


    • Edited by Hessc Friday, December 14, 2012 3:15 AM Correction of LINQ query
    • Proposed as answer by Yann DuranModerator Friday, December 14, 2012 5:18 AM
    • Marked as answer by Angie Xu Wednesday, December 19, 2012 11:57 PM
    Friday, December 14, 2012 3:13 AM

All replies

  • In VB you might use something like this.

    Dim q = From x In Me.DataWorkSpace.MyDataSource.MyEntity

    Where (x.MyProperty.Id = Me.MyProperty.Id) AndAlso (x.Date = System.Date.Today)

    Select x

    Dim r = q.SingleOrDefault

    If (r IsNot Nothing) Then

    'Your calculation here.

    EndIf


    • Edited by Hessc Friday, December 14, 2012 3:15 AM Correction of LINQ query
    • Proposed as answer by Yann DuranModerator Friday, December 14, 2012 5:18 AM
    • Marked as answer by Angie Xu Wednesday, December 19, 2012 11:57 PM
    Friday, December 14, 2012 3:13 AM
  • Hi etechpartner

    I will mark Hessc's reply as answer, if the marked answer is not helpful to solve your problem, please unmark and give quick response.

    With regards


    Angie xu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 20, 2012 12:10 AM
  • When the user selects a value from a modal_picker I want to run a query based on that to populate another field. I tried doing it "beforeApplyingChanges" but nothing seemed to work.

    Can you provide any guidance on that?

    Thanks.


    bill ross

    Monday, December 23, 2013 8:40 PM