I have a scenario as follow:
- Project is using EF Database first (so not modifying the generated EF model)
- We don't create new Model nor using AutoMapper as it is overkill for project.
- Often time, all column from database will be return, exclude some sensitive data.
- Suggestion to create an anonymous type (eg: x => new { }) and specific binding one by one is also tedious (as it has many field to return and also need to specify explicitly one by one the fields)
So, after certain considerations, I am thinking excluding properties in linq queries result is the best solution for my case.
Expectation: Expect that we can EXCLUDE some properties. Note that ExcludeProp should already exclude select those properties when generate linq to sql queries. How can I do that?
For example:
entities.tblCampaigns.Include(x => x.tblUser).Include(x => x.tblCampaignsPhotos)
.ExcludeProp(x => x.UpdatedDT) // Ignore campaign updated datetime
.ExcludeProp(x => x.tblUser.Password) // Ignore user password
.ExcludeProp(x => x.tblCampaignPhotos.tblCampaign) // Ignore entire campaign reference in campaign photos