Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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#中的Union以外的东西来提高查询性能?_C#_Sql_Union - Fatal编程技术网

如何使用C#中的Union以外的东西来提高查询性能?

如何使用C#中的Union以外的东西来提高查询性能?,c#,sql,union,C#,Sql,Union,我有一个名为Product的对象,它的属性为ProductItem和tags public class Shop{ public string Id {get; set;} public Product Products {get; set;} } public class Product{ public string Name {get; set;} public string Id {get; set;} public Tag Tags {ge

我有一个名为Product的对象,它的属性为ProductItem和tags

public class Shop{
    public string Id {get; set;}
    public Product Products {get; set;}   
}

public class Product{
    public string Name {get; set;}
    public string Id {get; set;}
    public Tag Tags {get; set;}
    public ProductItem ProductItems {get; set;}
    public Shop ShopInformation {get; set;}
}

public class Tag{
    public string Id {get; set;}
    public string name {get; set;}
}

public class ProductItem{
    public string Id {get; set;}
    public Tag Tags {get; set;}
}
我想从datacontext获取产品和标记中的所有标记 我使用这个查询

var result = from shop in dataContext.Shop
             select new Response
             {
                 Id = shop.Id,
                 Tags = (from product in dataContext.Product
                 where product.ShopInformation.Id == shop.Id
                 from productTag in 
                 product.Tags.Union(product.ProductItems.SelectMany(s => s.Tags))
                 select productTag.Name).Distinct(),
             };

但是,性能非常慢,因此我想知道是否有方法可以更快地收集所有标记。

生成的SQL查询是什么样子的?您看过执行计划了吗?productItems是产品的内部连接,并与产品中的所有SKU联合。对所有店铺重复该过程生成的SQL查询是什么样子的?您看过执行计划了吗?productItems是产品的内部连接,并与产品中的所有SKU联合。这一过程对所有的商店都是重复的