0

I have a model class which also includes a fileContent (byte[]) property. Is it possible to exclude the fileContent property from getting filled with its content when the class is loaded/retrieved?

// My Class/Model
public partial class empLeaves
{
    public string empId { get; set; }
    public string leaveId { get; set; }
    public System.Guid fsguid { get; set; }
    public string fileNameOrig { get; set; }
    public byte[] fileContent { get; set; }

}

Loading/retrieving data in controller/dataLayer as follows:

emp_leaves = db.empLeaves.Include(i => i.empLeaveApprovals.Select(q => q.approvalType))
    .Include(i => i.empmaster)...
    .Where(m => m.ID == id).Single();

In my view, I am passing the model object, which carries the whole data, which is unnecessary. the file content would be required only when the user chooses to download it.

I know I could use a ViewModel, but have kept it for last, since this table has a lot of columns and keeps adding up very often. Seeking any other easier way out. Another option [dirty option] i have thought of is to set the column value to null before passing to view. But i would prefer that fileContent is not loaded at all.

Federico Dipuma
  • 17,655
  • 4
  • 39
  • 56
Arfath
  • 143
  • 7
  • *I know I could use a ViewModel, but have kept it for last, since this table has a lot of columns and keeps adding up very often.* - What exactly does this mean? The amount of columns is irrelevant, as there are mapping interfaces available to use. Look into [AutoMapper](https://github.com/AutoMapper/AutoMapper), because using a Viewmodel is a great approach to this problem. – Grizzly Oct 19 '17 at 12:03
  • Just go with the ViewModel approach! – Ric Oct 19 '17 at 12:07

0 Answers0