function for get list of documents name only with distinct...
public static List<DocumentTypeModel> GetUploadedDocumentsName(int TicketId)
{
    List<DocumentTypeModel> documents = new List<DocumentTypeModel>();
    using (var db = new UnitOfWork())
    {
        documents = db.tbl_TrnTicketDocument.Get(x => x.FK_TicketId == TicketId && x.IsActive == true).Select(s => new DocumentTypeModel()
        {
            DocumentTypeNameEnglish = s.tbl_MstDocumentType.DocumentTypeNameEnglish
        }).Distinct().ToList();
    }
    return documents;
}
currently result is this -
Affidavit in Case of Cancelled Will/No Will
Affidavit in Case of Cancelled Will/No Will
Allotment Letter
Allotment Letter
Death Certificate
Death Certificate
Lease Deed
Lease Deed
Photo Identity of Applicant
Photo Identity of Applicant
Possession Letter
Possession Letter
Registered/Unregistered Will
Registered/Unregistered Will
You can use groupby and select first option like this:
List<DocumentTypeModel> documents = new List<DocumentTypeModel>();
using (var db = new UnitOfWork())
{
   documents = db.tbl_TrnTicketDocument.Get(x => x.FK_TicketId == TicketId && x.IsActive == true).Select(s => new DocumentTypeModel()
   {
   DocumentTypeNameEnglish = s.tbl_MstDocumentType.DocumentTypeNameEnglish
   }).ToList();
   documents = documents.GroupBy(x => x.DocumentTypeNameEnglish).Select(g => g.First());
}
                        Distinct() doesn't work like you tried on objects. Use IComparer to get this working https://support.microsoft.com/en-us/kb/320727
Create a comparer class
public class DocumentTypeModelComparer: IComparer
{
  int IComparer.Compare(object a, object b)
 {
   if(a.Id == b.ID)
     return 0;
   else
     return 1;
  }
}
Now in your lambda expression
 documents = db.tbl_TrnTicketDocument.Get(x => x.FK_TicketId == TicketId && x.IsActive == true).Select(s => new DocumentTypeModel()
        {
            DocumentTypeNameEnglish = s.tbl_MstDocumentType.DocumentTypeNameEnglish
        }).ToList().Distinct(new DocumentTypeModelComparer()).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With