나는 다음과 같은 구조를 가지고 자신의 날짜가에서 가장 발행 수와 날짜로부터 diferrent 경우LINQ C# 질문
class A
{
public Int32 ID {get; set;}
public DateTime Date {get;set;}
}
목록 alreadyCreated, 목록 newlyCreated 내가 새로 생성의 ID를 가져올를 벌써 만들었 어. alreadyCreated는 newlyCreated를 포함합니다. empty.I 또한 날짜 시간과 노력했다
var result = (from ClassA newCreated in newlyCreated
group newCreated by newCreated .Date
into groups
// select the "correct" date
let correctDate = (from ge in group
from ce in newlyCreated
where groupEvents.Count() == groupEvents.Max(gr =>groupEvents.Count())
&& ge.ID != ce.ID
select ge).FirstOrDefault()
//select the "incorrect" ones
let incorrectDates= (from ge in group
join ce in newlyCreated on ge.ID equals ce.ID
where DateTime.Compare(ge.EventDateGMT,eventWithCorrectDate.EventDateGMT) !=0
select ge).ToList()
select new { CorrectDate= correctDate, IncorrectDates= incorrectDates}).FirstOrDefault();
모든 것은 내가 새롭게하고 다른 날짜로 만든 oldycreated 한 기본적으로 경우 DateTime.Compare를 제외하고 잘 작동의 incorrectDates의 목록입니다 : 나는 다음과 같은 LINQ를 .Equals와 date1! = date2. 같은 결과. where DateTime.Compare(ge.EventDateGMT,eventWithCorrectDate.EventDateGMT) !=0
이 없으면 새로 작성된 레코드가 모두 반환됩니다 (alreadyCreated의 목록에는 newlyCreated의 목록이 포함됨). 어디에 문제가 있습니까?
는'ge.EventDateGMT' 무엇입니까 데 도움이? –
DateTime 유형 – Elena
이 아닌 ge.EventDateGMT.Subtract (eventWithCorrectDate.EventDateGMT) .CompareTo (new TimeSpan (0))! = 0이 작동했습니다. 다른 방법으로 linq를 변경해야합니다. – Elena