Pranshu Saxena
Pranshu Saxena

Reputation: 145

Filter a list Using Linq C#

public class Orgs
{            
     public int Id { get; set; }
     public DateTime OrgCreationTime { get; set; }
     public string AppUserId { get; set; }                 
     public virtual ICollection<OrgPersonRelationshipDomain> ManyOrgPersonRelationship { get; set; }
}

public class OrgPersonRelationshipDomain
{
        //public int ID { get; set; }
        public int OrgId { get; set; }
        public virtual OrgDomain Org { get; set; }
        public bool IsDeleted { get; set; }
}

var orgs = await _context.Org.Where(x => x.Id == request.Id).ToListAsync();

How to filter list where "orgs" should give result with IsDeleted!= true? Result I am getting is only ManyOrgPersonRelationship item but I want Orgs properties included in it. `

Upvotes: 0

Views: 97

Answers (1)

mohamadreza firooz
mohamadreza firooz

Reputation: 99

Try this :

var orgs = _context.Org.Where(x => x.AppUserId == userId && x.ManyOrgPersonRelationship.Any(x => x.IsDeleted != false)).ToList();

Upvotes: 1

Related Questions