The operator '==' cannot be applied to the group of operand methods' or 'string'

I have the following code:

  <span>@Model.LicenseHolder.LegalPerson.ContactDetails.Select(x => x.Name == "Fish")</span>

When I ran this, I get an error message:

The operator '==' cannot be applied to the group of operand methods' or 'string'

I don’t understand why I understand this.

Here you can see the ContactDetails image: 'enter image description here

I want to access the ContactDataType property and compare the Name property that is inside ContactDataType, but I don't know how to do this. So basically I want:@Model.LicenseHolder.LegalPerson.ContactDetails.ContactDataType.Select(x => x.Name == "PrimaryPhone")

+4
source share
3 answers

You need to apply it to the Wherenot function Select:

<span>@Model.LicenseHolder.LegalPerson.ContactDetails.Where(x => x.Name == "Fish").FirstOrDefault()</span>

Or even better:

<span>@Model.LicenseHolder.LegalPerson.ContactDetails.FirstOrDefault(x => x.Name == "Fish")</span>
+7
source

, Name, , , , .
: ContactDataType, DebuggerDisplay, Detail, Id PersonId. Name. , () Name :

@Model.LicenseHolder.LegalPerson.ContactDetails.Select(x => x.Name() == "Fish")

IEnumerable<Boolean>, , , - .
, ?

@Model.LicenseHolder.LegalPerson.ContactDetails
      .FirstOrDefault(x => x.Name() == "Fish")
      .ContactDataType 

ContactDetail ContactDataType, Name() "Fish".

+2

Api selection is reserved for selecting properties, in your case you want to filter by property value, so use Where: <span>@Model.LicenseHolder.LegalPerson.ContactDetails.Where(x => x.Name == "Fish").FirstOrDefault().Select(x => x.Name)</span>

0
source

Source: https://habr.com/ru/post/1652829/


All Articles