1

I really didn't know how to properly describe it, but here is the problem:

    [Key]
    public int ImageID { get; set; }
    public virtual List<Gallery> Galleries { get; set; }
    public virtual User CreatedBy { get; set; }

    [Key]
    public int GalleryID { get; set; }
    public string Name { get; set; }
    public virtual List<Image> Images { get; set; }

    images = (from i in _ctx.Images
              from g in i.Galleries
              where i.Galleries.Count() <= 0 || g.GalleryID != 0
              select i).ToList();

I already tried sveral iterations, and I just can't get it working.

What I'm trying to do is to select images that are not in gallery.

Images are not in that particular gallery, or they are not in any gallery at all.

1 Answer 1

1

Just select images which does not have any galleries (that mean none of galleries have these images):

images = _ctx.Images.Where(i => !i.Galleries.Any()).ToList();

EF will generate NOT EXISTS subquery in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.