找不到的查询模式的实现 [英] Could not find an implementation of the query pattern
问题描述
在我的Silverlight应用程序,我想创建使用LINQ数据库连接。
首先,我添加一个新的LINQ to SQL类,我的表称为tblPersoon拖动到它。
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();
但在tblPersoon它给了我下面的错误。
But at tblPersoon it gives me the following error.
找不到源类型的查询模式的实现
SilverlightApplication1.Web.tblPersoon。 如果'未找到。
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为我的表生成的类可以在这里找到: http://pastebin.com/edx3XRhi
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?
感谢您。
推荐答案
是 tblPersoon
实施的IEnumerable< T>
?您可能需要使用做到这一点:
Is the tblPersoon
implementing IEnumerable<T>
? You may need to do it using:
var query = (from p in tblPersoon.Cast<Person>() select p).Single();
此类型的错误(找不到查询模式的实现的),通常情况下发生:
This kind of error (Could not find an implementation of the query pattern) usually occurs when:
- 您缺少LINQ命名空间的使用(
使用System.Linq的
) - 输入您要查询不实施
的IEnumerable&LT; T&GT;
- You are missing LINQ namespace usage (
using System.Linq
) - Type you are querying does not implement
IEnumerable<T>
修改
除了事实上,你的查询类型( tblPersoon
),而不是财产 tblPersoons
,你还需要一个上下文实例(类,定义了 tblPersoons
属性),像这样的:
Apart from fact you query type (tblPersoon
) instead of property tblPersoons
, you also need an context instance (class that defines tblPersoons
property), like this:
public tblPersoon GetPersoonByID(string id)
{
var context = new DataClasses1DataContext();
var query = context.tblPersoons.Where(p => p.id == id).Single();
// ...
这篇关于找不到的查询模式的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!