EF Core - add conditional where based on field value

c# entity-framework entity-framework-core linq

Popular Answer

Final response is grateful to Gert Arnold for offering guidance in the OP comments.

    var query = from e in context.Events
                    join c in context.EventCategories on e.CategoryId equals c.CategoryId
                    join o in context.Owners on e.OwnerId equals o.OwnerId
                    where !e.IsDeleted && (e.DateType == 1 && e.StartDateTimeUtc <= DateTime.UtcNow && e.EndDateTimeUtc >= DateTime.UtcNow) //specific date
                                           || (e.DateType == 2 && e.Period >= DateTime.UtcNow.Month && e.Year >= DateTime.UtcNow.Year) // month
                                           || (e.DateType == 3 && e.Period >= DateTime.UtcNow.Month / 3 && e.Year >= DateTime.UtcNow.Year) //quarter
1
12/31/2018 2:12:43 PM






Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow