none
Dynamic LINQ query error: Overload resolution failed .... RRS feed

  • Question

  • I have some limited experience in the creation of normal LINQ to SQL queries but I now want to find a method of generating dynamic queries that will respond to user selections in various DropDownLists on my ASP.NET 3.5 web page. The following link to Scott Guthrie's blog article on dynamic LINQ queries looked like it would provide a potential solution:

    http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

    Unfortunately, I can't get dynamic LINQ queries to work. I have downloaded the VB Dynamic Query Library, copied Dynamic.vb into my ASP.NET site and referenced System.Linq.Dynamic in my VB.NET code behind page. However, my page fails with the compilation error message "Overload resolution failed because no accessible 'Where' can be called with these arguments" on the following line of code: 

    Recipients = myDBC.Entrants.Where("FirstName = 'David'") 
    
    

    I am probably making a very basic error somewhere. Any help would be much appreciated.

    David 

    Monday, November 23, 2009 11:19 AM

Answers

  • Problem now resolved!!!

    I had been doing my testing on a live test version of my website. However, a short time ago I found out that a test on my local machine ran ok. I then realised that the local version of Dynamic.vb was more recent than the version uploaded to my ISP. Upgrading this file fixed the online problem.

    The strange thing is, I have no recollection of ever modifying the Dynamic.vb file after its initial creation (which was a straight copy from the Dynamic Linq Library downloaded from Microsoft). Nothing in that file came from me. Perhaps something prompted me several days ago to recopy the Dynamic.vb just after I had uploaded my original version to my ISP and I then forgot to refresh the online version. Perhaps I'm going senile..... 

    Whatever I did wrong has wasted two days of my life. Grrrrrrrrr.

    Thanks to everyone (especially Kashif) for their patient assistance along the way.

    David 
    • Marked as answer by haggis999 Wednesday, November 25, 2009 9:27 PM
    Wednesday, November 25, 2009 6:18 PM

All replies

  • Since you include single quote at the string 'David' , The lamba expression (while parsing this string) will throw exceptions

    It may work if you would make a simple change

    Recipients = myDBC.Entrants.Where("FirstName = @0","David")


    Hope this helps

    Jbasingh




    Tuesday, November 24, 2009 6:59 AM
  • Hi Jbasingh,
    Thanks for the suggestion but that just changes the error message to "Overload resolution failed because no accessible 'Where' accepts this number of arguments".

    My own feeling is that I have not fully activated the Dynamic LINQ Library but I don't know what other steps might be necessary to do this (beyond what I stated in my OP).

    David
    Tuesday, November 24, 2009 10:18 AM
  • Do you have a using or imports statement for System.Linq.Dynamic in the file header?

    C£:
    using System.Linq.Dynamic;

    VB:
    Imports System.Linq.Dynamic

    Kristofer - Huagati Systems Co., Ltd.
    Cool tools for Linq-to-SQL and Entity Framework:
    huagati.com/dbmltools (add-in with new features for Visual Studio 2008's L2S and EF designers)
    huagati.com/L2SProfiler (Query profiler for Linq-to-SQL and LLBLGen Pro)
    Tuesday, November 24, 2009 10:24 AM
  • Yes, I have Imports System.Linq.Dynamic at the top of my VB.NET code behind page.

    David
    Tuesday, November 24, 2009 10:41 AM
  • Am I the only one here trying to use the Dynamic LINQ Library?

    David

     
    Tuesday, November 24, 2009 6:27 PM
  • These are extension methods:

    Where<T>(this IQueryable<T> source, string predicate, params object[] values)

    so any IQueryable can use this method:

    var query = from m in myDBC.Entrants
                     select m;

    var result = query.Where("FirstName = @0", "David");

    hope this helps.


    kashif
    Tuesday, November 24, 2009 8:12 PM
  • Hi Kashif,
    I'm not quite sure what you are trying to tell me. Apart from being in C# rather than VB.NET, your code does not look much different from what I have been using already. Note that the line of code in my OP is preceded by:

    Dim Recipients As IQueryable(Of Entrant)

     

    I must be doing something wrong but what can it be?

    David

    Tuesday, November 24, 2009 8:38 PM
  • open the Dynamic.vb class and see if there are any warnings on DynamicExpression.  There might an ambiguity due to that


    kashif
    Tuesday, November 24, 2009 8:53 PM
  • I have opened Dynamic.vb in Visual Web Developer 2008 Express but there are no warnings or errors.

    David
    Tuesday, November 24, 2009 9:45 PM
  • Hi David,

    Do you get any errors about namespace or just about the Where function?
    When you use the dynamic.cs file, pay attention to the namespce should be included (the same as the example).
    And also keep the other CS files with a common namespace, for example, winapp1.

    Best Regards
    Yichun Feng
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, November 25, 2009 8:41 AM
  • Hi Yichun,
    I am using VB.NET, not C#.

    The only error I am aware of is the one relating to the Where function. As I have already stated, I have Imports System.Linq.Dynamic at the top of my VB.NET code behind page.

    I am still a newbie working on my first ASP.NET 3.5 website and I don't really understand your comments about other files with a common namespace. Please clarify. Apart from importing namespaces from elsewhere, such as System.Linq.Dynamic, I have not knowingly created any namespaces of my own.

    David

     
    Wednesday, November 25, 2009 9:40 AM
  • Hey David,

    I just created a quick sample app in VB.NET and it seems to work fine.  One thing you have to be careful of is that in property's page of the application, there is no namespace defined.  you would need to include Namespace name within the code file.  the sample has one page, default.aspx.  let me know if there is a way i can send the aspx file.

     


    kashif
    Wednesday, November 25, 2009 10:14 AM
  • Hi Kashif,
    I'm new to this MSDN forum (I normally use the forums at http://forums.asp.net/). Is there any way to send private messages here? I would prefer to give you my email address privately rather than attracting the spam merchants by publishing it in a post to this forum.

    What do you mean by the "property's page of the application"? The controls on my web pages have properties but I am not aware of any property page for my 'application' (i.e. ASP.NET web site)? If it exists, where do I find it? Are you actually talking about my web.config file?   

    David 
    Wednesday, November 25, 2009 10:45 AM
  • In the solution explorer, right click the project and select properties.  This is the property page.  In the application tab, there is default namespace defined.  Remove this entry and make sure to add Namespace in the code file. 

    i am signed in on ASP.NET forums as 'PVT'.


    kashif
    Wednesday, November 25, 2009 10:57 AM
  • Kashif,
    The Property Pages box that appears when I right click on my project in Solution Explorer does not contain any tabs and nothing called 'Application'. Instead, I have options to set Common Properties and Configuration Properties. In case it is relevant, please note that I am using VWD 2008 Express.

    I will try to send you a private message on the ASP.NET forum.

    David
    Wednesday, November 25, 2009 11:11 AM
  • i am signed in on ASP.NET forums as 'PVT'.


    kashif

    I can't find a user on the ASP.NET forums with the name of PVT (or Kpbutt). However, there is a user called Kashif. Is that you? My own username on those forums is the same as here, i.e. haggis999

    David
    Wednesday, November 25, 2009 11:27 AM
  • you have created a web site instead of web application that is why you don't have the property page as i have mentioned.  no worries.  i have created a tested as a sample web site as well.
    kashif
    Wednesday, November 25, 2009 11:38 AM
  • you have created a web site instead of web application....
    kashif

    What is the difference?

    David
    Wednesday, November 25, 2009 11:41 AM
  • Kashif,
    Thanks for that useful info. I'm a self-taught ASP.NET programmer and there are large gaps in my knowledge!

    Are you able to send your sample aspx page to my haggis999 identity on the ASP.NET forum?

    David

    EDIT: According to one of my textbooks, VWD 2008 Express only supports Web Site Projects, not Web Application Projects. That explains why I was unfamiliar with Web Application Projects. 
    • Edited by haggis999 Wednesday, November 25, 2009 12:18 PM
    Wednesday, November 25, 2009 11:49 AM
  • i am unable to locate you on ASP.NET forum.  if you see my name, 'PVT', drop a message.  i don't think MSDN would appreciate it being used as messaging tool

    Regards,


    kashif
    Wednesday, November 25, 2009 12:10 PM
  • i am unable to locate you on ASP.NET forum... 


    kashif


    I am puzzled as to why you can't find me on the ASP.NET forums. I have made 399 posts there using the name of haggis999. My most recent post is on the same topic as on this forum.

    You can link to it here: http://forums.asp.net/t/1495938.aspx

    David
    Wednesday, November 25, 2009 12:24 PM
  • I did the same as Kashif, i.e. created a simple test web site that exploits the Dynamic Linq Library. It works!!! I don't get any "Overload resolution failed because no accessible 'Where' accepts this number of arguments" error messages.

    There must be something in my real website that is interfering with the operation of the Dynamic Linq Library. The trick is to find out what.....

    David
    Wednesday, November 25, 2009 3:16 PM
  • Problem now resolved!!!

    I had been doing my testing on a live test version of my website. However, a short time ago I found out that a test on my local machine ran ok. I then realised that the local version of Dynamic.vb was more recent than the version uploaded to my ISP. Upgrading this file fixed the online problem.

    The strange thing is, I have no recollection of ever modifying the Dynamic.vb file after its initial creation (which was a straight copy from the Dynamic Linq Library downloaded from Microsoft). Nothing in that file came from me. Perhaps something prompted me several days ago to recopy the Dynamic.vb just after I had uploaded my original version to my ISP and I then forgot to refresh the online version. Perhaps I'm going senile..... 

    Whatever I did wrong has wasted two days of my life. Grrrrrrrrr.

    Thanks to everyone (especially Kashif) for their patient assistance along the way.

    David 
    • Marked as answer by haggis999 Wednesday, November 25, 2009 9:27 PM
    Wednesday, November 25, 2009 6:18 PM