Reputation: 17
Is there a way to select multiple properties using the .Select()
query?
Something like this
model.Owners = eventResponse.Records.Select(x => x.Owner.Name && x.Subject).ToList();
Now I know that syntax doesn't work and it's pseudo-code, but is there a way to do something that produces the same result?
Upvotes: 0
Views: 78
Reputation: 382
Yes. If it is connected via foreign key, then you should need to use .include extension. It's working for sure, especially for pseudo-code.
model.Owners = eventResponse.Records.include("Owner").Select(x => x.Owner.Name && x.Subject).ToList();
Upvotes: 0
Reputation: 184
You should use anonymous type:
model.Owners = eventResponse.Records.Select(x => new {Name = x.Owner.Name, Subject = x.Subject)).ToList();
Upvotes: 4
Reputation: 19486
You can create an anonymous type or a tuple:
eventResponse.Records.Select(x => new { Name = x.Owner.Name, Subject = x.Subject }).ToList();
Or...
eventResponse.Records.Select(x => (Name: x.Owner.Name, Subject: x.Subject)).ToList();
Upvotes: 2
Reputation: 858
You could use a tuple like:
model.Owners = eventResponse.Records.Select(x => (x.Owner.Name, x.Subject)).ToList();
Upvotes: 1