找不到查询模式的实现 [英] Could not find an implementation of the query pattern

查看:30
本文介绍了找不到查询模式的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Silverlight 应用程序中,我尝试使用 LINQ 创建数据库连接.首先,我添加一个新的 LINQ to SQL 类,并将名为tblPerson"的表拖入其中.

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.tblPerson'.找不到哪里".

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

即使我尝试以下操作:

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

它给我一个错误,说找不到选择"!

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

为我的表生成的类的代码可以在这里找到: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?

谢谢.

推荐答案

tblPerson 是否实现了 IEnumerable?您可能需要使用:

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 命名空间用法(using System.Linq)
  • 您查询的类型没有实现 IEnumerable

编辑:

除了您查询类型 (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆