Reputation: 2209
I have a model that looks like this
[Column("StatusId")]
public FileStatus Status { get; set; }
public int Id { get; set; }
I also have an enum that looks like this.
public enum FileStatus
{
MessageInProgress,
MessageDone,
NoMessage
}
I am pulling data from my repository to populate data variable below
IEnumerable<MyFile> data = await _fileDataRepository.GetAllData(Id);
I want to filter data such that I will remove any record that has a status of MessageDone or NoMessage.
This code does not work for me.
data.where( x => x.Status != "MessageDone" | x.Status != "NoMessage")
How do I achieve the filtering?
Upvotes: 0
Views: 1037
Reputation: 1284
2 things you need to change:
FileStatus
is enum
and you use it as a string
. |
which is "boolean logical or" and you should use "Conditional logical and" &&
(You can use &
but most of the times is better to use conditional operator because of the laziness (For more details)).You should change it to:
data.where(x => x.Status != FileStatus.MessageDone && x.Status != FileStatus.NoMessage)
Or more simple:
data.where(x => x.Status == FileStatus.MessageInProgress)
Upvotes: 2