我有一些方法,可以返回最近360天、180天和90天内没有查询的联系人列表。
如果一个人在过去361天内没有被查询,那么在查询180天和90天时也会返回该人员信息。
我原本以为可以使用Except来实现,但这显然行不通。
public class Contacto
{
public int IdContacto { get; set; }
public string PrimerApellido { get; set; }
public string PrimerNombre { get; set; }
public string SegundoApellido { get; set; }
public string SegundoNombre { get; set; }
public object Telefonos { get; set; }
public int TipoTelefono { get; set; }
public int IdEstado { get; set; }
public DateTime? FechaArchivado { get; set; }
public DateTime? FechaConsulta { get; set; }
GetOldContacts方法
private static List<Contacto> GetOldContacts(int numberOfDays)
{
try
{
DateTime filter = DateTime.Now.AddDays(-numberOfDays);
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationSettings.Apiurl);
HttpResponseMessage response = client.GetAsync("api/ContactosDepurar?FechaInicial="+filter.ToShortDateString()).Result;
if (response.IsSuccessStatusCode)
{
return response.Content.ReadAsAsync<List<Contacto>>().Result;
}
else
{
System.Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
return null;
}
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
return null;
}
}
我的“Except”逻辑
IEnumerable<Contacto> contactosDoceMeses = GetOldContacts(ConfigurationSettings.Ciclo3Dias);
IEnumerable<Contacto> contactosSeisMeses = GetOldContacts(ConfigurationSettings.Ciclo2Dias).Except<Contacto>(contactosDoceMeses);
IEnumerable<Contacto> contactosTresMeses = GetOldContacts(ConfigurationSettings.Ciclo1Dias).Except<Contacto>(contactosSeisMeses);
问题在于第二个查询返回了我在第一个查询中的那些物品,而不应该这样。