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));