2
model.SectionControlTabs.ForEach(x =>
{
    x.EffectiveDate = x.EffectiveDate?.Split(' ')[0];
    x.LinkedWorkControlEffectiveDate = x.EffectiveDate != null? model.WorkControls
    .Where(y => DateTime.Parse(y.EffectiveDate) <= DateTime.Parse(x.EffectiveDate))
    .OrderByDescending(y => DateTime.Parse(y.EffectiveDate))
    .Select(y =>  new { CoverSelectionControl = y.CoverSelectionControl.ToString(),
        UserSelectionControl = y.UserSelectionControl.ToString()})
    .DefaultIfEmpty()
    .First().ToString(): "";
});

CoverSelectionControl and UserSelectionControl are not passed to the same named fields of their SectionControlTab, I have tried two seperate select statements but the second cant see the UserSelectionControl and I also have another field I wish to copy. If call the x.LinkedWorkControl... again it will be a duplication.

Above using complex defined types I just need to read from a parent and update the children for a viewModel.

How do I update a number of fields without using new????

1 Answer 1

2

You could use Tuple.Create but that basically hides the problem (and, until C# 7, has worse looking syntax). C#'s way of expressing a set of fields is as an object (as of C# 6.0). You create an object with new. There's no way around this (using Linq).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.