Could not find query template implementation

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 the tblPersoon table into it.

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

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

But in tblPersoon this gives me the following error.

Could not find query template implementation for source type 'SilverlightApplication1.Web.tblPersoon. "Where" not found.

And even if I try the following:

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

This gives me an error saying โ€œSelectโ€ was not found!

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

What causes this and how can I solve it?

Thank.

+72
c # sql linq silverlight wcf
Nov 21 '11 at 17:18
source share
10 answers

Is tblPersoon IEnumerable<T> tblPersoon ? You may need to do this using:

 var query = (from p in tblPersoon.Cast<Person>() select p).Single(); 

Such an error (could not find the implementation of the query template) usually occurs when:

  • You are missing out on using the LINQ namespace ( using System.Linq )
  • The type you are requesting does not implement IEnumerable<T>

Edit

In addition to requesting the type ( tblPersoon ) instead of the tblPersoons property, you also need a context instance (the class that defines the tblPersoons property), for example:

 public tblPersoon GetPersoonByID(string id) { var context = new DataClasses1DataContext(); var query = context.tblPersoons.Where(p => p.id == id).Single(); // ... 
+194
Nov 21 '11 at 17:45
source share

You may need to add a using statement to the file. The Silverlight class template does not include it by default:

 using System.Linq; 
+134
Nov 21 '11 at 17:38
source share

Make sure these links are included:

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

Then add using statement

 using System.Linq; 
+20
Mar 02 '15 at 13:36
source share

I had a similar problem with generating strongly typed datasets, full error message:

Could not find query template implementation for source type 'MyApp.InvcHeadDataTable'. "Where" not found. Consider explicitly specifying the type of the variable range "string".

From my code:

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

So, I did as he suggested, and explicitly indicated the type:

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

What worked.

+6
Aug 12 '15 at 8:38
source share

You lack equality:

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

where condition should result in a boolean.

OR you should not use where at all:

 var query = (from p in tblPersoon select p).Single(); 
+5
Nov 21 '11 at 17:31
source share

I had the same error as described in the header, but for me it was just a Microsoft access 12.0 oledb installation distributed for use with LinqToExcel.

0
Jan 11 '16 at 20:19
source share

Hi The easiest way to do this is to convert this IEnumerable to Queryable

If this is a query, then query execution 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 enable System.Linq . Thus, your error will be fixed.

0
Feb 25 '17 at 5:56 on
source share

For those of you (like me) who have lost too much time due to this error:

I got the same error: "Could not find the implementation of the query template for the source type" DbSet ", but the solution for me was to fix the error 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 followed the repository pattern in the ASP.NET manual) looked like this:

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

My problem arose because of the initial setup of my DbContext when I used DbSet as generic instead of type.

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




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

0
Jun 17 '18 at 0:23
source share

I had the same error, but for me it was due to the presence of a database and a table with the same name. When I added the ADO.NET Entity Object to my project, it incorrectly generated what I wanted in my database context file:

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

which was supposed to be:

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

As well as

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

which I donโ€™t really need, so I commented on this.

I tried to pull my table, for example, to my controller when I received 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 fixed the context of my database and everything was fine after that.

0
Oct 22 '18 at 20:08
source share

I had this problem and adding

 using System.Linq; 

solved it.

0
Jun 04 '19 at 15:53 โ€‹โ€‹on
source share



All Articles