2013-03-01 2 views
0

내가 유창함 자 NHibernate와 함께 자동 매핑을 사용하고, 그리고 NHibernate에 밀리 초 벗겨하지 않도록하려면 다음 코드를 사용하고있는 타임 스탬프 열 비교와 쿼리 :이 아주 잘 작동LINQ의 NHibernate에

public class TimestampTypeConvention : IPropertyConvention, IPropertyConventionAcceptance 
{ 
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria) 
    { 
     criteria.Expect(x => x.Type == typeof(DateTime) || x.Type == typeof(DateTimeOffset)); 
    } 

    public void Apply(IPropertyInstance instance) 
    { 
     instance.CustomType<TimestampType>(); 
    } 
} 

를, 그래서 데이터는 데이터베이스에 올바르게 저장됩니다. 나는 다음과 같은 LINQ 쿼리를 실행할 때

그러나, 나는 그것을 기대 일치하지 않습니다

bool isDuplicate = session.Query<TagData>() 
          .Any(x => x.TagName == message.EventTag.TagName 
           && x.TimeStamp == message.EventTag.TimeStamp.UtcDateTime); 

결과 SQL은 다음과 같습니다,이 작동하지 않는 이유를 설명 :

select tagdata0_."Id" as column1_0_, tagdata0_."TagName" as column2_0_, 
tagdata0_."TimeStamp" as column3_0_, tagdata0_."Value" as column4_0_, 
tagdata0_."QualityTimeStamp" as column5_0_, tagdata0_."QualitySubstatus" as column6_0_, 
tagdata0_."QualityExtendedSubstatus" as column7_0_, tagdata0_."QualityLimit" as column8_0_, 
tagdata0_."QualityDataSourceError" as column9_0_, tagdata0_."QualityTagStatus" as column10_0_, 
tagdata0_."TagType" as column11_0_ from "TagData" tagdata0_ 
where tagdata0_."TagName"=:p0 and tagdata0_."TimeStamp"=:p1 limit 1; 
:p0 = 'VALVE_HW_CMD' [Type: String (0)], 
:p1 = 01.03.2013 16:51:30 [Type: DateTime (0)] 

어떻게 전체 정밀도를 사용하도록 생성 된 쿼리를 강제 적용 할 수 있습니까?

BTW, message.EventTag.TimeStamp이있는 DateTimeOffset

답변

0

내가 로깅 출력에 속지되었다 : (PostgreSQL의 로그 파일에서 가져온) 실제 SQL은 다음과 같습니다

그것을하는 진짜 이유있어
SELECT this_."Id" as column1_0_0_, this_."TagName" as column2_0_0_, 
this_."TimeStamp" as column3_0_0_, this_."Value" as column4_0_0_, 
this_."QualityTimeStamp" as column5_0_0_, this_."QualitySubstatus" as column6_0_0_, 
this_."QualityExtendedSubstatus" as column7_0_0_, this_."QualityLimit" as column8_0_0_, 
this_."QualityDataSourceError" as column9_0_0_, this_."QualityTagStatus" as column10_0_0_, 
this_."TagType" as column11_0_0_ FROM "TagData" this_ 
WHERE this_."TimeStamp" = ((E'2013-03-01 16:51:30.509498')::timestamp) 

예상대로 작동하지 않았습니다. DateTimeDiff은 16 : 51 : 30.5094984의 값을 가지지 만 PostgreSQL의 timestamp 열은 마이크로 초의 정확도를 가지고 있습니다. 이는 마이크로 초의 정확도의 1/10을 의미합니다. 완전한 정확성을 유지하는 유일한 방법은 데이터베이스에 틱을 저장하는 것입니다.

(다른 스레드에서 MassTransit의 중복 메시지를 거의 또는 전혀받지 못했기 때문에 중복 된 데이터베이스가 있는지 항상 확인하지는 못했습니다.) O2, 멀티 스레딩의 놀라운 점