I have the following SQL snippet within a select statement:
CASE
WHEN wot.id LIKE '%Correct%' THEN 'Corrective'
WHEN wot.id LIKE '%Pred%' THEN 'Preventative'
ELSE 'OTHER'
END
AS worktype
which I have translated into LINQ to SQL like this:
WorkType = groupItem.Key.Id.Contains("Correct") ? "Corrective" : "OTHER" ||
WorkType = groupItem.Key.Id.Contains("Pred") ? "Preventative" : "OTHER"
If I add one or the other by itself into the select statement, then the query works fine. However, when I add the OR statement and try to use both statements in the select, I get an “Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access” error.
I’ve seen the other questions about this error and in those cases they rename one of the statements (ex. WorkType, Work_Type) in order to fix the problem. However, Worktype is the name of my output field so I need to have both be WorkType.
Any ideas?
Solution :
it should be
Problem:
because problem with your code is
you are assigning value to worktype two time which is nopt possible
And even if you write the code like
this will return boolean value either true or false…