I have two main entities in my model. Report (also Report Table) and ReportFolder(also Table)
[DataContract(IsReference = true)]
public partial class Report
{
public Report()
{
this.DataSources = new List<DataSource>();
CreationDate = DateTime.Now;
}
[DataMember]
public long Id { get; set; }
[DataMember]
public long ReportFolderId { get; set; }
[DataMember]
public virtual ReportFolder ReportFolder { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string ReportContent { get; set; }
......
}
[DataContract(IsReference = true)]
public partial class ReportFolder
{
public ReportFolder()
{
this.Reports = new List<Report>();
this.Folders = new List<ReportFolder>();
CreationDate = DateTime.Now;
}
[DataMember]
public long Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public long? ParentId { get; set; }
[DataMember]
public virtual ICollection<Report> Reports { get; set; }
[DataMember]
public virtual ICollection<ReportFolder> Folders { get; set; }
.....
}
So the problem is , I am using my report in two scenarios, in one I need to load all the ReportFolders with Reports in this scenario I do not want load ReportContent(it is a heavy filed). In the other scenario I want to load and save a Report with the all fields. Based on my search entityframework does not support partially loading fields.
Then I decided to inherit form Report and make another class called ReportWithContent and in this class map ReportContent field (also remove this filed form Report class) and use this two class in different scenarios (sending one form client to server and respond the other to the client to prevent to much data transfer) but I was not successful it needed a discriminator which I do not have(EF exception). I am thinking of having Report without mapping ReportContent in this case whatever action I should use ReportContent I will have to use plain Sql which I do not know is a good practice or not.