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
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:
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.
Source: Stackoverflow.com