C# Linq、OData和WCF:&x201C;不支持方法join”;
我正在尝试从多个表恢复和显示数据。o我做过这样的多次连接:C# Linq、OData和WCF:&x201C;不支持方法join”;,c#,visual-studio-2010,linq,odata,C#,Visual Studio 2010,Linq,Odata,我正在尝试从多个表恢复和显示数据。o我做过这样的多次连接: var prod = from product in context.PRODUCT join islocated in context.ISAUDITEDIN on product.PRODUCT_ID equals islocated.PRODUCT_ID join location in context.LOCATION on islocated.LOCATION_ID equals location.LOCATI
var prod = from product in context.PRODUCT
join islocated in context.ISAUDITEDIN on product.PRODUCT_ID equals islocated.PRODUCT_ID
join location in context.LOCATION on islocated.LOCATION_ID equals location.LOCATION_ID
orderby location.LOCATION_ID
group new
{
Location_ID = location.LOCATION_ID,
Product_ID = product.PRODUCT_ID
} by location.LOCATION_ID into locat
select new {
Location_ID = locat.Key,
Product = locat
};
其中,context是导致web服务调用的OData。这个链接起作用了:当我做一个简单的选择时,我能够恢复数据。
然后,我想显示结果中的数据。所以我创造了一个词汇:
Dictionary<string,List<ProductModel>> dict = new Dictionary<string,List<ProductModel>>();
foreach (var locat in prod) {
List<ProdctModel> products = new List<ProductModel>();
foreach (var p in locat.Product)
{
products.Add(new ProductModel(p.Location_ID, p.Product_ID));
}
dict.Add(locat.Location_ID.ToString(), products);
}
但当我运行时,我有以下几点:
“the method join is not supported”
Ligne 131 : Dictionary<string,List<ProdctModel>> dict = new Dictionary<string,List<ProdctModel>>();
Ligne 132 : foreach (var locat in prod) {
“不支持方法联接”
Ligne 131:Dictionary dict=new Dictionary();
Ligne 132:foreach(产品中的var locat){
如何解决这个问题?我已经看到了一些使用method.Expand()代替join的方法,但我不知道如何使用它:你能帮我吗
谢谢!我从未将odata与linq一起使用过,但我假设您无法加入不同的远程资源。请尝试先将对象放入内存,然后进行加入:
var products = context.PRODUCT.ToList();
var islocateds = context.ISAUDITEDIN.ToList();
var locations = context.LOCATION.ToList();
var prod = from product in products
join islocated in islocateds on product.PRODUCT_ID equals islocated.PRODUCT_ID
join location in locations on islocated.LOCATION_ID equals location.LOCATION_ID
orderby location.LOCATION_ID
group new
{
Location_ID = location.LOCATION_ID,
Product_ID = product.PRODUCT_ID
} by location.LOCATION_ID into locat
select new {
Location_ID = locat.Key,
Product = locat
};
请记住,这将下载所有3个表
编辑
另外,创建字典时出现异常的原因是“prod”变量是IEnumerable,它仅在执行“foreach”时执行请求或者类似的东西。我认为是相同的@Dawoodabasi,但好的答案是什么?@Leandro根据连接方法仍然不受支持。Derbie,作为web服务的消费者,对此无能为力。要使其工作,必须为服务使用不同的框架。假设存在这样的框架。
var products = context.PRODUCT.ToList();
var islocateds = context.ISAUDITEDIN.ToList();
var locations = context.LOCATION.ToList();
var prod = from product in products
join islocated in islocateds on product.PRODUCT_ID equals islocated.PRODUCT_ID
join location in locations on islocated.LOCATION_ID equals location.LOCATION_ID
orderby location.LOCATION_ID
group new
{
Location_ID = location.LOCATION_ID,
Product_ID = product.PRODUCT_ID
} by location.LOCATION_ID into locat
select new {
Location_ID = locat.Key,
Product = locat
};