Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello i have following entities

C#
public class FileInformation : Entity
       {

           public string FileName { get; set; }
           public string FilePath { get; set; }
           public string Clientid { get; set; }
           public List<ChangeInformation> ChangeInformations { get; set; }
           public FileInformation()
           {
               this.ChangeInformations = new List<ChangeInformation>();
           }
       }
       public class ChangeInformation
       {

           public string FileName { get; set; }
           public string OldFileName { get; set; }
           public long FileSize { get; set; }
           public DateTime ModifiedDate { get; set; }
           public string HashValue { get; set; }
           public string DeviceID { get; set; }
           public DateTime CreationDate { get; set; }
           public string Status { get; set; }
           public ChangeInformation()
           {

           }
       }


i want to get all the fileinformation which have not been deleted

What I have tried:

C#
var files = finfo.Where(n => n.ChangeInformations.Any(x=>x.Status !="Deleted");
Posted
Updated 24-Feb-16 23:33pm
v2
Comments
[no name] 25-Feb-16 4:59am    
It looks ok. What is the value you are getting files variable or any error?
dan!sh 25-Feb-16 5:07am    
Update your question with the error details if any or details of what is not working.
srilekhamenon 25-Feb-16 5:10am    
changeinformation can have multiple information like change,Rename or delete.
it is returning the first row

1 solution

Your code will return the FileInformation object if it has any ChangeInformation object with status not as Deleted.

Now, if an object has statuses as changed and delete, it will be returned. I will recommend changing it to this:

Here, we are checking if any status is deleted. If yes, do not take it.

C#
var files = finfo.Where(n => !n.ChangeInformations.Any(x=>x.Status == "Deleted");


If deleted is always going to be on top and ChangeInformation is sorted in descending order of date, you can just check the first item if the status is deleted. If not select it. Something like this:

C#
finfo.Where(x =>
            (x.ChangeInformations != null && x.ChangeInformations.Count > 0 && x.ChangeInformations[0].Status != "Deleted")
            );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900