How to get all the birthdays of today?

后端 未结 5 1863
南方客
南方客 2021-01-23 09:21

Does anyone know how to make a Linq query that gets all the birthdays of today? The code below doesn\'t work :

var getBirthdays = 
    orgContext.CreateQuery<         


        
5条回答
  •  不思量自难忘°
    2021-01-23 10:18

    I solved my problem based on the example of "Peter Majeed" and using "LinqKit"!

    var predicate = PredicateBuilder.False();
    for (int i = Math.Min(140, DateTime.Today.Year - 1900); i > -1; i--)
    {
        DateTime cleanDateTime = new DateTime(DateTime.Today.AddYears(-i).Year, DateTime.Today.AddYears(-1).Month, DateTime.Today.AddYears(-i).Day);
        predicate = predicate.Or(p => p.BirthDate == cleanDateTime.ToUniversalTime());
    }
    var getBirthdays = (from c in orgContext.CreateQuery().AsExpandable().Where(predicate)
                         select c).ToList();
    

    The above query gave me the correct result! Thx to all who helped me!

提交回复
热议问题