How to get all the birthdays of today?

后端 未结 5 1861
南方客
南方客 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:08

    You can use QueryExpression (it works for Microsoft CRM Plugin)

    public EntityCollection getBirthdateList(IOrganizationService orgsService)
        {
            List birthdays = new List(); 
    
            //makes sure no CRM unsupported dates are passed (less than 1/1/1900)
            for (int i = Math.Min(140, DateTime.Today.Year - 1930); i > -1; i--)
            {
                //adds a different date per year
                birthdays.Add
                (
                    DateTime.Now.AddYears(-i).ToString("yyyy-MM-dd")
                ); 
            }
    
           
            // Instantiate QueryExpression 
            var query = new QueryExpression("contact");
    
            // Define filter QEquote.Criteria
            var queryfilter = new FilterExpression();
            query.Criteria.AddFilter(queryfilter);
    
            // Define filter 
            queryfilter.FilterOperator = LogicalOperator.Or;
            queryfilter.AddCondition("birthdate",ConditionOperator.In,birthdays.ToArray());
            return orgsService.RetrieveMultiple(query); ;
        }
    

提交回复
热议问题