[英]send email birthdate to all contact in CRM 365 with workflow C#?
如何使用工作流c#向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 };
我在linq條件中收到錯誤:
無效的“ where”條件。 實體成員正在調用無效的屬性或方法
嘗試從日期中刪除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();
您不需要“價值”。 見下面的代碼
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; }
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.