I develop a simple application, something like a chat where every message may contain text and files. Entities are related like this:
Message group -> every message group has a collection of messages -> every message has a property 'FileCollection' -> 'File collection' has 4 collections: Images, Video, Audio, Files. All of them has the same relations in database. To show this logic here is my query to get all message groups with their entities:
var messageGroups = await _db.MessageGroups
.Where(mg => mg.UserId == id)
.Include(m => m.Messages).ThenInclude(mes => mes.FileCollection.Images)
.Include(m => m.Messages).ThenInclude(mes => mes.FileCollection.Video)
.Include(m => m.Messages).ThenInclude(mes => mes.FileCollection.Audio)
.Include(m => m.Messages).ThenInclude(mes => mes.FileCollection.Files)
.ToListAsync();
The problem is that every type of file (Image, Audio etc.) has a 'Data' column in Db (property in EF Core) which contains their blob data. I want to exclude all blob from query, because query becomes extremely heavy loading all user files from Db. Something like this (but exclude method does not exist):
.Include(m => m.Messages).ThenInclude(mes => mes.FileCollection.Video).exclude(video => video.Data);
Is there any way to use explicit loading at the end of the query? Or maybe there are attributes like [JsonIgnore] which excludes class property from Json serializing? Or any other method?
If it helps: ImageFile, AudioFile and others inherit from File super class:
public class File
{
[Column("id")]
public int Id { get; set; }
[Column("content_type")]
public string ContentType { get; set; }
[Column("file_name")]
public string FileName { get; set; }
[Column("length")]
public long Length { get; set; }
[Column("related_file_collection_id")]
public int FileCollectionId { get; set; }
public FileCollection FileCollection { get; set; }
}
public class ImageFile : File
{
[Column("data")]
public byte[] Data { get; set; }
}
I need all properties from 'File' class without 'Data' property from it's child classes.