Based on @Craig Stuntz's answer and a similar DTO, for my solution I created a partial model class (in a separate file) and a return object method with the way I want, using only the properties that will be needed.
namespace TestApplication.Models { public partial class Employee { public object ToObject() { return new { EmployeeID = EmployeeID, Name = Name, Username = Username, Office = Office, PhoneNumber = PhoneNumber, EmailAddress = EmailAddress, Title = Title, Department = Department, Manager = Manager }; } } }
And then I call it simply on return:
var employee = dbCtx.Employees.Where(x => x.Name == usersName).Single(); return employee.ToObject();
I think the accepted answer is faster and easier, I just use my method to keep all my results consistent and dry.
Pat Migliaccio May 10 '16 at 17:50 2016-05-10 17:50
source share