LINQ Between Operator

If you express it as a where clause it may just work out of the box with LINQ to SQL, if you can construct an appropriate expression. There may be a better way of doing this in terms of the expression trees – Marc Gravell may well be able to improve it – but it’s … Read more

Checking for duplicates in a List of Objects C#

You need to reference System.Linq (e.g. using System.Linq) then you can do var dupes = dupList.GroupBy(x => new {x.checkThis, x.checkThat}) .Where(x => x.Skip(1).Any()); This will give you groups with all the duplicates The test for duplicates would then be var hasDupes = dupList.GroupBy(x => new {x.checkThis, x.checkThat}) .Where(x => x.Skip(1).Any()).Any(); or even call ToList() or … Read more

What’s better for creating distinct data structures: HashSet or Linq’s Distinct()?

Anthony Pegram has said it the best. Use the right tool for the job. I say this because a Distinct or HashSet isn’t that big different when it comes to performance. Use a HashSet when the collection should always hold only distinct stuffs. It also tells the programmer that you cant add duplicates to it. … Read more

How to debug a LINQ Statement

Yes it is indeed possible to pause execution midway through a linq query. Convert your linq to query style using lambda expressions and insert a Select statement that returns itself somewhere after the point in the linq that you want to debug. Some sample code will make it clearer – var query = dataset.Tables[0].AsEnumerable() .Where … Read more

How to use union all in LINQ?

Concat is the LINQ equivalent of UNION ALL in SQL. I’ve set up a simple example in LINQPad to demonstrate how to use Union and Concat. If you don’t have LINQPad, get it. In order to be able to see different results for these set operations, the first and second sets of data must have … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)