none
Why I Cant use computed Field in the Query ???

    Question

  • Hey Please help, i want to use the computed field in Query Designer.How can i achieve this in an Easiest Manner (For Desktop, Coding in VB)


    Sharad Soni

    Tuesday, May 15, 2012 1:38 PM

Answers

  • hi Sharad

    It is better to use lightswitch global query to filter your report. But you can also directly filter the report from the DevExpress report designer itself.

    Please see the below image, in my case Address Summery is a computed string property.

    Hope this help...


    Rashmi Ranjan Panigrahi

    • Marked as answer by Sharad Soni Thursday, May 24, 2012 12:15 PM
    Thursday, May 24, 2012 8:39 AM

All replies

  • Hi

    In LightSwitch you can't use computed property in your query designer or in ProcessQuery method. You have to compute your value inside the query code only. For more details please follow this thread.

    Regards


    Rashmi Ranjan Panigrahi

    Tuesday, May 15, 2012 2:18 PM
  • Hello Sharad,

    as Rashmi said, computed fields cant be used "out-of-the-box" in query designer, as computed fields do not actualy exist in the table - they are just shown on screen by LightSwitch.

    but you can use the same "math" computed field has - and use it in query at PreProcess time.

    just make sure that you are working with REAL query, i.m. one generated from data source table, and not just with screen level query.

    in PreProcessQuery you will have free hands to do all things that are demanded by your app.

    i hope this helps! 

    regards,

    M.

    Tuesday, May 15, 2012 4:37 PM
  • I want to build the Query just for the Report Purpose. I am using DevExpress XtraReports.

    There is no parameter been passed, just i need the filtration of the data which is to be shown in the report.

    If any Alternate method is there to have the Filtration of data from XtraReports, please suggest me that. And if Not than please give me the Idea of how to write PreProcessQuery and what it is and where to write. And Will it work for Report ????


    Sharad Soni

    Wednesday, May 16, 2012 9:17 AM
  • Hi Sharad,

    As you mentioned "here is no parameter been passed, just i need the filtration of the data ", I suggest you to refer to the codes I provide below:

    1.I create a Table Person with LastName FirstName and computed property FullName:

            partial void FullName_Compute(ref string result)
            {
                result = LastName + " " + FirstName;
            }

    2.I create a Query for this table which named QueryForFullName.

    Then I create PreprocessQuery method for this query:

            partial void QueryForFullName_PreprocessQuery(ref IQueryable<Person> query)
            {
                query = query.Where(item => (item.LastName + " " + item.FirstName).Contains("o"));
            }

    Please pay attention to this :the computed property FullName haven't been computed at this time. So I repeat the compute code in the PreprocessQuery again.

    3.Please see the result:

    • Proposed as answer by babloo1436 Thursday, May 17, 2012 6:07 AM
    Thursday, May 17, 2012 6:00 AM
  • Thanks Otomii Lu,

    But Can you give me the Coding in VB.

    It will be more helpful to me.


    Sharad Soni

    Thursday, May 17, 2012 6:11 AM
  • But Can you give me the Coding in VB.

    It will be more helpful to me.

    Not to be funny, but there are numerous code translaters available on the internet, surely you can translate the code yourself??

    Xander

    Thursday, May 17, 2012 6:25 AM
  • Hi,

    there is the VB code :

            Private Sub FullName_Compute(ByRef result As String)
                ' Set result to the desired field value
                result = LastName + " " + FirstName
            End Sub

            Private Sub QueryForFullName_PreprocessQuery(ByRef query As System.Linq.IQueryable(Of LightSwitchApplication.Person))
                query = query.Where(Function(item) ((item.LastName + " " + item.FirstName).Contains("o")))
            End Sub

    Hope helpful.

    Thursday, May 17, 2012 6:38 AM
  • Novascape you stand true.

    Otomii lu, my Computed filed was not as simple as to join two string it its some thing like this....

    Private Sub BalanceAmount_Compute(ByRef result As Decimal)
                ' Set result to the desired field value
                Dim bal As Decimal = 0
                For Each x As CashIncomeByLocal In CashIncomeByLocals
                    If x.LocalLR.Id = Me.Id Then
                        bal += x.Amount
                    End If
                Next
                For Each x As BankIncomeByLocal In BankIncomeByLocals
                    If x.LocalLR.Id = Me.Id Then
                        bal += x.Amount
                    End If
                Next
                result = bal - Me.Profit
    End Sub

    Now i want to filer the data i.e i want a query listing the records where BalanceAmount is = 0

    How can I implement this ??


    Sharad Soni

    Thursday, May 17, 2012 6:39 AM
  • Hey how can i implement the Logic of above given code in the PreProccessQuery ????

    Sharad Soni

    Thursday, May 24, 2012 6:28 AM
  • As the query is IQueryable , not IEnumerable. So you cannot do it as what you have mentioned.

    (IQueryable is only for one condition.)

    A customized Silverlight DataGrid can be used to show the items.(But it will be more complex)

    There is some example on the web.

    Thursday, May 24, 2012 6:35 AM
  • hi Sharad

    It is better to use lightswitch global query to filter your report. But you can also directly filter the report from the DevExpress report designer itself.

    Please see the below image, in my case Address Summery is a computed string property.

    Hope this help...


    Rashmi Ranjan Panigrahi

    • Marked as answer by Sharad Soni Thursday, May 24, 2012 12:15 PM
    Thursday, May 24, 2012 8:39 AM
  • Ohhh Thanks again Rashmi,

    It Worked.

    Thanks,


    Sharad Soni

    Thursday, May 24, 2012 12:15 PM
  • Hi Sharad and Babloo1436,

    I'm facing the same problem,but I cannot figure it out. Sorry for cannot get the idea you mentioned.

    Could you share more details about the solution. Big THX~

    Friday, May 25, 2012 1:31 AM
  • Hi SilverLightSwitch

    Can you please post a new question in this forum regarding your problem.


    Rashmi Ranjan Panigrahi

    Friday, May 25, 2012 4:11 AM