Answer the question
In order to leave comments, you need to log in
How to get records from a table based on a collection of keys?
This method is of interest:DbPicture[] GetImages(string[] keys)
public interface IContentRepository
{
void AddImage(DbPicture image);
void AddImages(DbPicture[] images);
DbPicture[] GetImages(string[] keys);
DbPicture GetImage(string key);
}
public class ContentRepository : IContentRepository
{
private readonly ContentDbContext _context;
public ContentRepository()
{
_context = new ContentDbContext();
}
public void AddImage(DbPicture image)
{
_context.Pictures.Add(image);
_context.SaveChangesAsync();
}
public void AddImages(DbPicture[] images)
{
_context.Pictures.AddRange(images);
_context.SaveChangesAsync();
}
public DbPicture[] GetImages(string[] keys)
{
return _context.Pictures. ??????????????????????;
}
public DbPicture GetImage(string key)
{
return _context.Pictures.Find(key);
}
}
Answer the question
In order to leave comments, you need to log in
I figured it out myself. Decided like this:
public DbPicture[] GetImages(string[] keys)
{
return _context.Pictures.Where(p => keys.Any(k => k == p.FileName)).ToArray();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question