【问题标题】:send email birthdate to all contact in CRM 365 with workflow C#?使用工作流 C# 向 CRM 365 中的所有联系人发送电子邮件生日?
【发布时间】:2025-12-19 18:30:06
【问题描述】:

如何使用工作流 向 CRM 365 中的所有联系人发送生日电子邮件?

我写的代码:

var today = DateTime.Today.AddYears(-90);
var contacts = from c in orgContext.CreateQuery<Contact>()
    where (c.BirthDate != null && c.BirthDate.Value.Month == today.Month)
    where (c.BirthDate != null && c.BirthDate.Value.Day == today.Day)
    select new { c.Id, c.LogicalName, c.BirthDate, c.FullName };

我在 where 条件中遇到错误:

“位置”条件无效。实体成员正在调用无效的属性或方法

【问题讨论】:

  • 您遇到了哪个错误?
  • “位置”条件无效。实体成员正在调用无效的属性或方法

标签: c# linq c# linq


【解决方案1】:

您不需要“价值”。见下面的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;


namespace Oppgave3Lesson1
{
    class Program
    {

        static void Main(string[] args)
        {
            Context orgContext = new Context();
            DateTime today = DateTime.Now;

            var contacts = from c in orgContext.CreateQuery<Contact>()
                           //remoived value
                           where (c.BirthDate != null && c.BirthDate.Month == today.Month)
                           where (c.BirthDate != null && c.BirthDate.Day == today.Day)
                           select new { c.Id, c.LogicalName, c.BirthDate, c.FullName };
        }
    }
    public class Context
    {
        public List<Contact> CreateQuery<Contact>()
        {
            return new List<Contact>
        }
    }

    public class Contact
    {
        public DateTime BirthDate { get; set; }
        public int Id { get; set; }
        public string LogicalName { get; set; }
        public string FullName { get; set; }
    }



}

【讨论】:

  • 非常感谢您的帮助,但我无法删除价值。我有这个错误:'DateTime?'不包含“月份”的定义,并且没有扩展方法“月份”接受“日期时间”类型的第一个参数?可以找到(您是否缺少 using 指令或程序集引用?)
【解决方案2】:

尝试从日期中删除Value 属性并使用ToList() 将结果集转换为列表

  var contacts = (from c in orgContext.CreateQuery<Contact>()
                   where (c.BirthDate != null && c.BirthDate.Month == today.Month
                                              && c.BirthDate.Day == today.Day)                      
                   select new { c.Id, c.LogicalName, c.BirthDate, c.FullName}).ToList();

【讨论】: