Distinct objects & distinct based on a specific propertie (in this case Mobile and Fax) by LINQ

//distinct objects
List<objects> listObjects = (from obj in db.Objects                             
                             select obj).Distinct().ToList();
//distinct based on a specific propertie (in this case Mobile and Fax)
List<Objects> listObjects = (from obj in db.Objects                             
                                select obj).GroupBy(n => new {n.Mobile, n.Fax})
                                           .Select(g => g.FirstOrDefault())
                                           .ToList();

Comments

Popular posts from this blog

How to use DbFunctions.TruncateTime

Microsoft Access Connectivity from C#

Tool 'dotnet-ef' failed to install. dotnet core