Отвечено Expiration Date alarm in lightswitch

  • 13. března 2012 8:31
     
      Obsahuje kód

    I've this code:

    Private Sub StartUp_Created()
                ' Write your code here.
                Dim a = Me.DataWorkspace.ApplicationData.ItemReciept.Where(Function(o) o.QualityCertificates.OrderBy(Function(q) q.RetestDate).FirstOrDefault < Today.Add(TimeSpan.FromDays(30)))
                Dim b = a.Execute.Count
    
                Me.ShowMessageBox("you have:" + b.ToString + " matrials with retest date before:" + Today.Add(TimeSpan.FromDays(30)))
    End Sub

    It's to find if there are "receipt items" may be expire soon.

    but, I got this error:

    FirstOrDefault is not supported.

    Then, I've changed the code to :

    Private Sub StartUp_Created()
                ' Write your code here.
                Dim a = Me.DataWorkspace.ApplicationData.ItemReciept.Where(Function(o) o.QualityCertificates.OrderBy(Function(q) q.RetestDate).Any < Today.Add(TimeSpan.FromDays(30)))
                Dim b = a.Execute.Count
    
                Me.ShowMessageBox("you have:" + b.ToString + " matrials with retest date before:" + Today.Add(TimeSpan.FromDays(30)))
    End Sub

    and I got this error:

    Operator '<' is not defined for types 'Boolean' and 'Date'.

    ______________________________________________

    So, Can you help me to fix this ?

Všechny reakce

  • 13. března 2012 21:14
     
     

    Please, can anyone help me ?????

    I've posted here because I know there is someone can show me to the right code.

  • 14. března 2012 5:05
     
     
    Should I post it in other forum ????
  • 14. března 2012 7:02
    Moderátor
     
      Obsahuje kód

    Based on your original code, although it doesn't compile, what I am able to understand is that you want a collection of ItemReceipts where the RetestDate of the earliest QualityCetificate is at most 30 days in the future. Or were you trying to achieve some other set of results.

    Would you agree that you can think of it as "all ItemReceipt instances where the RetestDate of any QualityCertificate is at most 30 days in the future? These should return equivalent results. The code for this query would look like:

    Dim futureDate As Date = Today.Add(TimeSpan.FromDays(30))
    Dim a = Me.DataWorkspace.ApplicationData.ItemReciepts.Where(Function(o) o.QualityCertificates.Any(Function(q) q.RetestDate < futureDate))


    Justin Anderson, LightSwitch Development Team

  • 14. března 2012 10:18
     
     

    I've do what you did tell me.

    But, when I hit F5 I get the error above .... Please help me .


  • 14. března 2012 10:44
    Moderátor
     
     Odpovědět Obsahuje kód

    What you can do is create a query off of the ItemReceipt entity and call that query from the Startup_Created method:

    1. Right-click on ItemReceipt in Solution Explorer and select Add Query. Name the query to whatever you want (let's say it's called Query1).

    2. Click on <QueryName>_PreprocessQuery method from the Write Code drop down of the query designer.

    3. Write the query code here, e.g.:

    Private Sub Query1_PreprocessQuery(ByRef query As System.Linq.IQueryable(Of LightSwitchApplication.ItemReciept))
        Dim futureDate As Date = Today.Add(TimeSpan.FromDays(30))
        query = query.Where(Function(o) o.QualityCertificates.Any(Function(q) q.RetestDate < futureDate))
    End Sub

    4. From the Startup_Created method, execute the query off of the ApplicationData property in the data workspace and use the results however you want (in the code you've provided, you are counting the results):

    Private Sub Startup_Created()
        Dim b = Me.DataWorkspace.ApplicationData.Query1().Execute().Count()
    End Sub

    Justin Anderson, LightSwitch Development Team

    • Označen jako odpověď IT_Technician 14. března 2012 11:37
    • Zrušeno označení jako odpověď IT_Technician 15. března 2012 20:54
    • Označen jako odpověď IT_Technician 19. března 2012 12:42
    •  
  • 14. března 2012 11:36
     
     

    It's worked finally.

    Thank you very much Justin Anderson.

    But, I have another question ... :)

    I've created the following query :

    and you can see the relationships here:

    I want to get all the items that don't have any price ... So, I've create that query. But, when I create search screen and use the UnPricedItems query as screen data to know what items I have without prices, nothing happen, the search screen appears with no items in it ... but I've create an Item receipt without give any price for that item.

    If you got it ... what should I do to fix that query ?

  • 15. března 2012 12:16
     
     

    But, when I execute the query I got this error :

    So, can anyone help me ?????? 

    please, I need the solution ASAP.

  • 15. března 2012 16:20
     
     

    Please, can anyone answer me ???

    What should I do to fix the error ??

  • 16. března 2012 16:09
     
     

    Please, help me to find the best solution for this query.

    I need it ASAP.

    B.R.

  • 16. března 2012 19:42
     
     

    Try

    = "Release"

    instead of

     Is "Release"

    Also change all your And to AndAlso


    Like Yann Said : "If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer". This will help people find the answers that they're looking for more quickly."

    • Navržen jako odpověď Nadjib Bait 16. března 2012 19:42
    • Zrušeno navržení jako odpověď IT_Technician 17. března 2012 12:29
    •  
  • 17. března 2012 6:55
     
     

    Still the same error .... :((

    What should I do ?

  • 17. března 2012 9:48
     
     
    ??????
  • 17. března 2012 11:20
     
     
    anyone here ???
  • 17. března 2012 21:02
     
     
    help me please, I'm new in VS lightswitch.
  • 17. března 2012 23:17
     
     
    No one will help me ??? :((((((
  • 18. března 2012 19:36
     
     

    Please, can anyone help ASAP ????

    I need that query, my project is not functioning right now. Because that query.

  • 19. března 2012 12:45
     
     Odpovědět

    I did it , yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeesssssssssss

    Finally.

    I've shared the solution here, to let anyone who face similar problem to fix it.

    • Označen jako odpověď IT_Technician 19. března 2012 12:45
    •