Reputation: 195
I have a property that executes a LINQ query. Why does it return a bool? How can I make it return an instance of my ORMClass?
public string ContactPersonName
{
get
{
return Convert.ToString(
Client.ContactPersons.Select(x => x.MainContactPerson == true).First()
);
}
}
I want some of
((ContactPerson)Client.ContactPersons.Select(x => x.MainContactPerson == true).First())).Name //typecast error
Upvotes: 0
Views: 62
Reputation: 2887
You're doing a Select
when you really want a Where
public string ContactPersonName
{
get
{
return Convert.ToString(
(
Client.ContactPersons.Where(x => x.MainContactPerson == true).First())
)
;
}
}
Upvotes: 0
Reputation: 75316
You should use Where
to filter instead of Select
Client.ContactPersons.Where(x => x.MainContactPerson).First();
For simpler:
Client.ContactPersons.First(x => x.MainContactPerson);
Upvotes: 5