【发布时间】:2014-04-02 17:32:35
【问题描述】:
我有两个类,客户端和用户。用户是客户端中的一个字段(有一个外键)。我正在尝试加入,获取所有客户和相关用户(这是一对一的)。
我正在使用实体框架和提供数据的网络服务。
目前我的所有客户都喜欢:
public DbSet<Client> getClients()
{
return context.Clients;
}
我还需要获取相关对象用户。我找到了一个告诉我这样做的例子:
public DbSet<Client> getClients()
{
return context.Clients.include(x => x.User);
}
这会引发异常,我需要使用 IQueryable。如果我更改我的功能,与 Web 服务的连接将无法正常工作。
我该如何做我想做的事?
编辑:
我从网络服务得到的例外是An error occurred while receiving the HTTP response to http://localhost:60148/WebService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
【问题讨论】:
-
有什么异常?
-
它无法通过 http 连接到我的网络服务。我可以在一小时内给你确切的例外情况......
-
@Paritosh 我添加了我遇到的问题的例外情况。
-
您是否从 wcf 服务返回 DbSet?我不认为这是可能的,可能是错误的。因为如果您通过 wcf 服务传递 if,IQueryable 将不起作用,因为这是传递查询,而 wcf 服务只需要返回数据。您可以尝试创建一个包含用户字段的自定义对象(ClientBasic),当您在服务中获取数据时,使用您需要返回的内容填充 ClientBasic 列表。
-
另外看起来有解决方法,试试这些链接:stackoverflow.com/questions/4291370/… 和 stackoverflow.com/questions/3341469/…
标签: asp.net entity-framework join iqueryable dbset