Expiration Date alarm in lightswitch
-
Tuesday, March 13, 2012 8:31 AM
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 SubIt'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 Suband I got this error:
Operator '<' is not defined for types 'Boolean' and 'Date'.
______________________________________________
So, Can you help me to fix this ?
- Moved by Justin AndersonMicrosoft Employee, Moderator Wednesday, March 14, 2012 6:50 AM Not related to VS11 Beta (From:LightSwitch in Visual Studio 11 Beta)
All Replies
-
Tuesday, March 13, 2012 9:14 PM
Please, can anyone help me ?????
I've posted here because I know there is someone can show me to the right code.
-
Wednesday, March 14, 2012 5:05 AMShould I post it in other forum ????
-
Wednesday, March 14, 2012 7:02 AMModerator
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
-
Wednesday, March 14, 2012 10:18 AM
I've do what you did tell me.
But, when I hit F5 I get the error above .... Please help me .
- Edited by IT_Technician Wednesday, March 14, 2012 10:19 AM
-
Wednesday, March 14, 2012 10:44 AMModerator
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 Sub4. 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 SubJustin Anderson, LightSwitch Development Team
- Marked As Answer by IT_Technician Wednesday, March 14, 2012 11:37 AM
- Unmarked As Answer by IT_Technician Thursday, March 15, 2012 8:54 PM
- Marked As Answer by IT_Technician Monday, March 19, 2012 12:42 PM
-
Wednesday, March 14, 2012 11:36 AM
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 ?
-
Thursday, March 15, 2012 12:16 PM
But, when I execute the query I got this error :
So, can anyone help me ??????
please, I need the solution ASAP.
-
Thursday, March 15, 2012 4:20 PM
Please, can anyone answer me ???
What should I do to fix the error ??
-
Friday, March 16, 2012 4:09 PM
Please, help me to find the best solution for this query.
I need it ASAP.
B.R.
-
Friday, March 16, 2012 7:42 PM
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."
- Proposed As Answer by Nadjib Bait Friday, March 16, 2012 7:42 PM
- Unproposed As Answer by IT_Technician Saturday, March 17, 2012 12:29 PM
-
Saturday, March 17, 2012 6:55 AM
Still the same error .... :((
What should I do ?
-
Saturday, March 17, 2012 9:48 AM??????
-
Saturday, March 17, 2012 11:20 AManyone here ???
-
Saturday, March 17, 2012 9:02 PMhelp me please, I'm new in VS lightswitch.
-
Saturday, March 17, 2012 11:17 PMNo one will help me ??? :((((((
-
Sunday, March 18, 2012 7:36 PM
Please, can anyone help ASAP ????
I need that query, my project is not functioning right now. Because that query.
-
Monday, March 19, 2012 12:45 PM
I did it , yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeesssssssssss
Finally.
I've shared the solution here, to let anyone who face similar problem to fix it.
- Marked As Answer by IT_Technician Monday, March 19, 2012 12:45 PM

