Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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# 我相信它。现在已修复。我尝试了you's示例,但它不起作用,这里的这部分产品c=e。当前为产品;在上下文中不存在任何其他提示我的错误它起作用了感谢堆我今天学到了一些新东西我的名字也是Kirk! if (Tab == "All-Items") { L_C#_Asp.net_Linq - Fatal编程技术网

C# 我相信它。现在已修复。我尝试了you's示例,但它不起作用,这里的这部分产品c=e。当前为产品;在上下文中不存在任何其他提示我的错误它起作用了感谢堆我今天学到了一些新东西我的名字也是Kirk! if (Tab == "All-Items") { L

C# 我相信它。现在已修复。我尝试了you's示例,但它不起作用,这里的这部分产品c=e。当前为产品;在上下文中不存在任何其他提示我的错误它起作用了感谢堆我今天学到了一些新东西我的名字也是Kirk! if (Tab == "All-Items") { L,c#,asp.net,linq,C#,Asp.net,Linq,我相信它。现在已修复。我尝试了you's示例,但它不起作用,这里的这部分产品c=e。当前为产品;在上下文中不存在任何其他提示我的错误它起作用了感谢堆我今天学到了一些新东西我的名字也是Kirk! if (Tab == "All-Items") { List<Product> temp = new List<Product>(); List<Product> Products2 = new List<Product>(); fo


我相信它。现在已修复。我尝试了you's示例,但它不起作用,这里的这部分产品c=e。当前为产品;在上下文中不存在任何其他提示我的错误它起作用了感谢堆我今天学到了一些新东西我的名字也是Kirk!
if (Tab == "All-Items")
{
    List<Product> temp = new List<Product>();
    List<Product> Products2 = new List<Product>();
    foreach (Filter filter in Filters)
    {                        
        List<Product> products = (from p in db.Products where p.Discontinued == false
                                  && p.DepartmentId == qDepartment.Id
                                  join f in db.Filters on p.Id equals f.ProductId
                                  join x in db.ProductImages on p.Id equals x.ProductId
                                  where x.Dimension == "180X180"
                                  && f.Name == filter.Name /*Filter*/
                                  select new Product
                                  {
                                      Id = p.Id,
                                      Title = p.Title,
                                      ShortDescription = p.ShortDescription,
                                      Brand = p.Brand,
                                      Model = p.Model,
                                      Image = x.Path,
                                      FriendlyUrl = p.FriendlyUrl,
                                      SellPrice = p.SellPrice,
                                      DiscountPercentage = p.DiscountPercentage,
                                      Votes = p.Votes,
                                      TotalRating = p.TotalRating
                                  }).ToList<Product>();

        foreach (Product p in products)
        {
            temp.Add(p);
        }                        

        IEnumerable temp2 = temp.GroupBy(x => x.Id).Distinct();
        IEnumerator e = temp.GetEnumerator();
        while (e.MoveNext()) {
            Product c = e.Current as Product;
            Products2.Add(c);
        }
    }
    pf.Products = Products2;// return type must be List<Product>                
}
    //overridden Equals() method from the Object class, determines equality based on order number
    public override bool Equals(object obj)
    {
        bool equal;
        if (this.GetType() != obj.GetType())
            equal = false;
        else
        {
            Order temp = (Order)obj;
            if(OrderNumber == temp.OrderNumber)
                equal = true;
            else
                equal = false;
        }
        return equal;
    }

    //overridden GetHashCode() method from Object class, sets the unquie identifier to OrderNumber
    public override int GetHashCode()
    {
        return OrderNumber;
    }
IEnumerable temp2 = temp.GroupBy(x => x.Id).Distinct();         
IEnumerator e = temp.GetEnumerator();   // <- why temp and not temp2???
-Key: 1
   -Product (Id = 1)
-Key: 2
   -Product (Id = 2)
   -Product (Id = 2)
var groups = temp.GroupBy(x => x.Id);
var distinctItems = groups.Select(g => g.First());

foreach (var item in distinctItems)
{
    // do stuff with item
    Products2.Add(item);
}