1
Good afternoon, I’m running a C# Net Core application, using lambda for database context handling. I have one question, and that is: I have a list of objects with these two attributes: Name and Startdate. Something like:
List<Operations> operations = new List<Operations>();
operations.Add(new Operation() { Name: "Exemplo 1", StartDate: "2018-07-02 00:00:00" };
operations.Add(new Operation() { Name: "Exemplo 2", StartDate: "2017-05-01 13:00:00" };
Now I would like to do a lambda in my context, iterating this list with a condition with the operator "OR". Something that would look like this in SQL:
SELECT
*
FROM
contact t
WHERE
(t.OperationName = "Exemplo 1" AND t.ContactDate > "2018-07-02 00:00:00")
OR (t.OperationName = "Exemplo 1" AND t.ContactDate > "2017-05-01 13:00:00")
But I’m not getting it. The conditions within the parentheses are separated by AND, when they relate to the same object, and separating the objects by OR. I’m using Lambda, something as follows below:
dbContext.Teste.Where(x => x...);
@EDIT: A Fiddle I made to demonstrate my problem: https://dotnetfiddle.net/DqvOx4
In this Fiddle, I can only do Where with the first obj of Operations, but I need to iterate through all objects. Does anyone have any idea how to do this using Lambda?
You have already written the answer with the solution. We do not write answers in the questions, nor do we put "solved" in the title
– Jefferson Quesado
Right, and as I mark that question has been resolved?
– Renan Gonzales
You already did when you marked your own response with the green old. See more here
– Jefferson Quesado