Reputation: 81
So I'm trying to use a linq expression in order to get certain properties associated with job orders that are related to those records. I'm having an issue actually accessing the values.
var accountManagerObject = (
from j in api.hc_joborderSet
where j.statecode == hc_joborderState.Active &&
j.hc_systemuser_hc_joborder_AccountManager != null &&
j.hc_ExpirationDate <= dateFilter
select new { accountmangerid = j.hc_AccountManager.Id, jobid = j.Id, jobName = j.LogicalName })
.ToLookup(o=>o.accountmangerid);
foreach (var jobId in accountManagerObject.ToList())
{
Console.WriteLine(jobId.Select(o=>o.jobName));
}
Instead of returning values my writeline is returning
System.Linq.Enumerable+WhereSelectEnumerableIterator
2[<>f__AnonymousType0
3[System.Guid,System.Guid,System.String],System.String] System.Linq.Enumerable+WhereSelectEnumerableIterator2[<>f__AnonymousType0
3[System.Guid,System.Guid,System.String],System.String] System.Linq.Enumerable+WhereSelectEnumerableIterator2[<>f__AnonymousType0
3[System.Guid,System.Guid,System.String],System.String] System.Linq.Enumerable+WhereSelectEnumerableIterator2[<>f__AnonymousType0
3[System.Guid,System.Guid,System.String],System.String] System.Linq.Enumerable+WhereSelectEnumerableIterator2[<>f__AnonymousType0
3[System.Guid,System.Guid,System.String],System.String]
Upvotes: 0
Views: 56
Reputation: 43936
Your Select()
returns an IEnumerable<string>
. And this instance's ToString()
method only gives you the type name.
You probably wanted to display the sequence of jobName
s. This can for example be done like that:
foreach (var jobId in accountManagerObject)
{
foreach(string jobName in jobId.Select(o=>o.jobName))
Console.WriteLine(jobName);
}
or shorter using string.Join
:
foreach (var jobId in accountManagerObject)
{
Console.WriteLine(string.Join(Environment.NewLine, jobId.Select(o=>o.jobName)));
}
Note that the .ToList()
call in your foreach
is unnecessary and should be ommitted. There is no need to create a new list from this LookUp
just to iterate through.
Upvotes: 2