1
我有一些方法可以返回我最近360天,180天和90天内未查询的联系人列表。LINQ除非没有按预期的方式工作
在过去的361天内没有被查询的一个人也将在180天和90天的查询中返回。
我想我能做到这一点与除,但是那肯定不是工作,
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;
}
}
而我除了逻辑
IEnumerable<Contacto> contactosDoceMeses = GetOldContacts(ConfigurationSettings.Ciclo3Dias);
IEnumerable<Contacto> contactosSeisMeses = GetOldContacts(ConfigurationSettings.Ciclo2Dias).Except<Contacto>(contactosDoceMeses);
IEnumerable<Contacto> contactosTresMeses = GetOldContacts(ConfigurationSettings.Ciclo1Dias).Except<Contacto>(contactosSeisMeses);
的问题是第二个查询是返回第一个项目,它不应该
任何更简单的方法? –
@ LuisValencia-MVP - 查看更新 –