Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将DataServiceOrderedQuery类型的对象强制转换为Microsoft.OData.Client.DataServiceCollection类型_C#_Wcf_Wcf Data Services - Fatal编程技术网

C# 无法将DataServiceOrderedQuery类型的对象强制转换为Microsoft.OData.Client.DataServiceCollection类型

C# 无法将DataServiceOrderedQuery类型的对象强制转换为Microsoft.OData.Client.DataServiceCollection类型,c#,wcf,wcf-data-services,C#,Wcf,Wcf Data Services,我有一个名为Foos的数据库表,其中包含foo类型的记录。我有另一个名为bar的表,其中包含bar类型的记录。我试图在数据库中查询集合foos,并将该集合放入类型为bar的记录中 类似这样的内容:(在第三方库中定义了foo和bar,我可以检查元数据,但不能更改它们) 如何将Container.Foos.Where(x=>x.someProperty==someRequirement)的结果分配给bar.Foos bar.Foos = Container.Foos.Where(x => x.

我有一个名为
Foos
的数据库表,其中包含
foo
类型的记录。我有另一个名为
bar
的表,其中包含
bar
类型的记录。我试图在数据库中查询集合
foos
,并将该集合放入类型为
bar
的记录中

类似这样的内容:(在第三方库中定义了
foo
bar
,我可以检查元数据,但不能更改它们)

如何将
Container.Foos.Where(x=>x.someProperty==someRequirement)
的结果分配给
bar.Foos

bar.Foos = Container.Foos.Where(x => x.someProperty == someRequirement);
应改为:

bar.Foos = new DataServiceCollection<Foo>(Container.Foos.Where(x => x.someProperty == someRequirement));
bar.Foos=newdataservicecollection(Container.Foos.Where(x=>x.someProperty==someRequirement));

还有一个例子。

将这一行添加到您的代码
var bob=Container.Foos.Where(someBool)
然后将鼠标光标悬停在
bob
上,查看
bob
的类型。提示-这不是一个集合。好的。。回报是不可能的。。。因此,我想问题是如何将
IQueryable
的结果放入
DataServiceCollection
?我将编辑这个问题。
newdataservicecollection
需要一个类型声明,因此答案是
bar.Foos=newdataservicecollection(Container.Foos.Where(x=>x.someProperty==someRequirement))
bar.Foos = Container.Foos.Where(x => x.someProperty == someRequirement);
bar.Foos = new DataServiceCollection<Foo>(Container.Foos.Where(x => x.someProperty == someRequirement));