Search code examples
c#subsonic

problem with Distinct query in subsonic 3


ProductCollection select = new 
        Select(Product.SupplierIDColumn).From<Product>().Distinct()
        .ExecuteAsCollection<ProductCollection>();

http://subsonicproject.com/docs/Distinct

From above example I am trying to get distinct category from my table but many problems comes

  1. I can not put column like this Product.SupplierIDColumn I dont know why my class EventListing has no intellisense for these columns
  2. Distinct() function is not available after From<EventListing>().

Solution

  • Interestingly, it looks like the SqlQuery class in SubSonic 2 had a Distinct() method, but the SqlQuery class in SubSonic 3 does not. You could try SS2 instead of 3, or if you are using 3, I suggest using Linq expressions instead. In other words, something like:

    var data = (from x in db.Products
                select x.SupplierId)
               .Distinct();
    

    -or-

    var data = db.Products.Select(x => x.SupplierId).Distinct();