[c#] Could not find an implementation of the query pattern

In my silverlight application I am trying to create a database connection using LINQ. First I add a new LINQ to SQL class, and drag my table called "tblPersoon" into it.

Then in my service file I try to execute the following query:

[OperationContract]
public tblPersoon GetPersoonByID(string id)
{
    var query = (from p in tblPersoon where p.id == id select p).Single();

But at tblPersoon it gives me the following error.

Could not find an implementation of the query pattern for source type 'SilverlightApplication1.Web.tblPersoon'. 'Where' not found.

And even when I try the following:

var query = (from p in tblPersoon select p).Single();

It gives me an error saying 'Select' not found!

Code for the generated class for my table can be found here: http://pastebin.com/edx3XRhi

What is causing this and how would I possibly solve this?

Thank you.

This question is related to c# sql silverlight wcf linq

The answer is


I had a similar issue with generated strongly typed datasets, the full error message was:

Could not find an implementation of the query pattern for source type 'MyApp.InvcHeadDataTable'. 'Where' not found. Consider explicitly specifying the type of the range variable 'row'.

From my code:

        var x =
            from row in ds.InvcHead
            where row.Company == Session.CompanyID
            select row;

So I did as it suggested and explicitly specified the type:

        var x =
            from MyApp.InvcHeadRow row in ds.InvcHead
            where row.Company == Session.CompanyID
            select row;

Which worked a treat.


For those of you (like me) that wasted too much time from this error:

I had received the same error: "Could not find implementation of query Pattern for source type 'DbSet'" but the solution for me was fixing a mistake at the DbContext level.

When I created my context I had this:

public class ContactContext : DbContext
    {
        public ContactContext() : base() { }

        public DbSet Contacts { get; set; }
    }

And my Repository (I was following a Repository pattern in ASP.NET guide) looked like this:

public Contact FindById(int id)
    {       
        var contact = from c in _db.Contacts where c.Id == id select c;
        return contact;
    }

My issue came from the initial setup of my DbContext, when I used DbSet as a generic instead of the type.

I changed public DbSet Contacts { get; set; } to public DbSet<Contact> Contacts { get; set; } and suddenly the query was recognized.


This is probably what k.m says in his answer, but since he mentioned IEnumerable<t> and not DbSet<<YourDomainObject>> I had to dig around in the code for a couple hours to find the line that caused this headache.


Make sure these references are included:

  • System.Data.Linq
  • System.Data.Entity

Then add the using statement

using System.Linq;

I had the same error as described by title, but for me it was simply installing Microsoft access 12.0 oledb redistributable to use with LinqToExcel.


You may need to add a using statement to the file. The default Silverlight class template doesn't include it:

using System.Linq;

You must have forgotten to add a using statement to the file like this:

using System.Linq;

Hi easiest way to do this is to convert this IEnumerable into a Queryable

If it is a queryable, then performing queries becomes easy.

Please check this code:

var result = (from s in _ctx.ScannedDatas.AsQueryable()
                              where s.Data == scanData
                              select s.Id).FirstOrDefault();
                return "Match Found";

Make sure you include System.Linq. This way your error will be resolved.


You are missing an equality:

var query = (from p in tblPersoon where p.id == 5 select p).Single();

where clause must result in a boolean.

OR you should not be using where at all:

var query = (from p in tblPersoon select p).Single();

I had the same error, but for me, it was attributed to having a database and a table that were named the same. When I added the ADO .NET Entity Object to my project, it misgenerated what I wanted in my database context file:

// Table
public virtual DbSet<OBJ> OBJs { get; set; }

which should've been:

public virtual DbSet<OBJ> OBJ { get; set; }

And

// Database?
public object OBJ { get; internal set; }

which I actually didn't really need, so I commented it out.

I was trying to pull in my table like this, in my controller, when I got my error:

protected Model1 db = new Model1();

public ActionResult Index()
{
    var obj =
        from p in db.OBJ
        orderby p.OBJ_ID descending
        select p;

    return View(obj);
}

I corrected my database context and all was fine, after that.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to silverlight

Get current index from foreach loop Value does not fall within the expected range Could not find an implementation of the query pattern How to programmatically set the Image source How to trigger event when a variable's value is changed? Format Date/Time in XAML in Silverlight The HTTP request is unauthorized with client authentication scheme 'Ntlm' Difference between SelectedItem, SelectedValue and SelectedValuePath How do I space out the child elements of a StackPanel? How to automatically select all text on focus in WPF TextBox?

Examples related to wcf

Create a asmx web service in C# using visual studio 2013 WCF Exception: Could not find a base address that matches scheme http for the endpoint WCF Service, the type provided as the service attribute values…could not be found WCF error - There was no endpoint listening at How can I pass a username/password in the header to a SOAP WCF Service The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'NTLM' Content Type application/soap+xml; charset=utf-8 was not supported by service The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8) maxReceivedMessageSize and maxBufferSize in app.config how to generate a unique token which expires after 24 hours?

Examples related to linq

Async await in linq select How to resolve Value cannot be null. Parameter name: source in linq? What does Include() do in LINQ? Selecting multiple columns with linq query and lambda expression System.Collections.Generic.List does not contain a definition for 'Select' lambda expression join multiple tables with select and where clause LINQ select one field from list of DTO objects to array The model backing the 'ApplicationDbContext' context has changed since the database was created Check if two lists are equal Why is this error, 'Sequence contains no elements', happening?