How can I use Distinct (C# statement)

edited November 2017
var query = from log in ViewLogs
join v in Vehicles on log.VehicleId equals v.VehilceId
join d in Sellers on v.SellerId equals d.SellerId
where v.IsActive && !v.IsDeleted && d.IsActive && d.IsPublic
select log.VehicleId;

I want the Distinct VehicleId to be listed. VehicleId is Guid. How to do this?

Also is there an option that I run a SQL query that generates the LINQ, i.e. the other way round?



  • edited November 2017
    How about:


    Note that you would be better off using association properties.
    var query = from log in ViewLogs
       let v = log.Vehicle
       let s = v.Seller
       where v.IsActive && v.IsDeleted && s.IsActive && s.IsPublic
       select log.VehicleId;
    You're in for a lot of unnecessary pain if you simply transliterate SQL into LINQ. For more info, read this:
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!