Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Get distinct list of foreign keys with Linq

$
0
0

Hi

I have classes:

  public class Deal
    {
        public int DealId { get; set; }
        public string Title { get; set; }
        public Dealproduct[] DealProducts { get; set; }

    }



    public class Dealproduct
    {
        public int ProductId { get; set; }
    }


    public class Product
    {
        
        public int ProductID { get; set; }
        public string ProductTitle { get; set; }
       
    }

Now I have List of deals  named selectedDeals.  and List of products is selection: 

	selectedDeals = selectedDeals.Where(x => (something));
        List<int> deviceIds = new List<int>();
//HERE IS THE PROBLEM. How do I put all the distinct productIds in the deviceIds list with Linq?
selection = selection.Where(x => deviceIds.Contains(x.ProductID ));

How do I put all the distinct productIds in the deviceIds list with Linq?

Please advice


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>