Forgive me if this has already been asked. I just started using LINQ. I have the following expression:
public static Expression<Func<TblCustomer, CustomerSummary>> SelectToSummary() { return m => (new CustomerSummary() { ID = m.ID, CustomerName = m.CustomerName, LastSalesContact =
I want to be able to populate LastSalesContact , which is a Person object.
The details I want to fill come from m.LatestPerson , so how can I match the fields from m.LatestPerson to LastSalesContact . I want the mapping to be reused, i.e. I do not want to do this:
LastSalesContact = new Person() {
Is it possible to use a static expression, for example:
public static Expression<Func<TblUser, User>> SelectToUser() { return x => (new User() {
UPDATE:
This is what I need to do:
return m => (new CustomerSummary() { ID = m.ID, CustomerName = m.CustomerName, LastSalesContact = new Person() { PersonId = m.LatestPerson.PersonId, PersonName = m.LatestPerson.PersonName, Company = new Company() { CompanyId = m.LatestPerson.Company.CompanyId, etc } } });
But I will reuse the creation of Person() about 10-15 different classes, so I donโt want the exact same code to be duplicated X times. I would also like to do the same for Company .
source share