none
LINQ in .NET 2010. - DynamicLinq Queries

    Question

  • Hi everyone,

    The request is to buiild a page on which I shall represent all the avaliable fields of a view that can be used by the user in order to build the query that will run by itself. I have done it and I am at the point that I have to create the LINQ select.

    In my page at the bigining I have imported the following:

    Imports WorkAtXYZ.NewNS.Linq.Dynamic
    Imports System.Linq.Expressions

    In order to construct the Select I use a function which investigate in my checkbox list all the items, and get the name of the fields for the selected ones.

    Finaly, my Select is the following :

    New(fldCorporateKey, fldFirstName, fldLastName, fldNormalDays_Remaining)

    and I proceed:

     Private Sub btnRunQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRunQuery.Click
            Dim cont As New workatXYZEntities_views
            Dim vw_Results As IQueryable
    Dim strSELECT As String = ConstructSELECT()
    vw_Results = cont.vw_AbsencesReportingModel.Select(strSELECT).Distinct

    and here I am getting the following error:

    'New' cannot be resolved into a valid type or function. Near simple identifier, line 2, column 8.

    Could you please help me? Is there something that I do not see?

    Thank you in advance.

    Tuesday, July 16, 2013 2:05 PM

All replies

  • Hi Anastasios,

    I tested your code but cannot call Distinct() method after Select() method.

    It works fine for me If I test the code like:

    vw_Results = cont.vw_AbsencesReportingModel.Distinct().Select(strSELECT)

    Best regards,


    Chester Hong
    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

    Friday, July 19, 2013 6:41 AM
  • Hi Chester, 

    Thank you very much for you answer and this is something that also others (from other forums) have answered me. But the issue is not solved. And as I have told you your proposal is matched with what also others propose to me as a solution. 

    I am still getting the same error. So I'll to give some more information on the project. 

    I have read that I have to include the following namespace in order to be able to have DynicLINQ Queries. 

    Imports WorkAtXYZ.NewNS.Linq.Dynamic
    Imports System.Linq.Expressions

    In the import above the posts was telling me that it is Syste.Linq.Dynamic but I do so, something is bypassed or replaced and in every file I have to include namespaces manually so I found this work around. 

    The whole function is the following: 

     Private Sub btnRunQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRunQuery.Click
    
            Dim cont As New workatXYZEntities_views
            Dim vw_Results As Object
    
            divResults.Visible = True
            divEntitySelector.Visible = False
            divRebuild.Visible = True
    
            Dim QueryToRun As Collection = ConstructQuery("Absences")
    
            Dim strWHERE As String = QueryToRun.Item(1).ToString
            Dim strSELECT As String = QueryToRun.Item(2).ToString
    
            If strWHERE <> "" Then
                vw_Results = cont.vw_AbsencesReportingModel.Where(strWHERE).Distinct().Select(strSELECT)
            Else
                vw_Results = cont.vw_AbsencesReportingModel.Distinct().Select(strSELECT)
            End If
    
    
            grdResults.DataSource = vw_Results
            grdResults.DataBind()
    
        End Sub

    Could you please check it for a while?

    Friday, July 19, 2013 10:55 AM