: 나는 특성으로 쿼리를 노출 할 때언제 보간 문자열을 평가합니까? 내가 다음 코드를 한
internal class Constants
{
internal static string Source { get; set; }
#region EvaluationRepository
internal static string QUERY_001 = [email protected]"
select
e.*
from {Source} e
where
e.id = @Id
";
internal static string QUERY_002 = [email protected]"
select
e.*
from {Source} e
where
[email protected]
and e.begindate >= @FromDate
and e.enddate <= @ToDate
";
internal static string QUERY_003
{
get
{
return [email protected]"
select
d.statusid [StatusId],
count(1) [Count]
from
(select e.statusid
from {Source} e
where e.begindate >= @FromDate and e.enddate <= @ToDate) d
group by d.statusid
";
}
}
#endregion
}
유일한 시간 {Source}
이 가득입니다. (QUERY_003)
필드으로 노출되면 작동하지 않습니다. (QUERY_001, QUERY_002)
이유를 설명 할 수있는 사람이 있습니까? 정적이기 때문에 (확실한 단어가 아닌지)? 그것은 런타임에 끝났다는 SQL :
정말, 문자열 보간은 여기에 빨간색 청어입니다. 당신은 효과적으로 "언제 필드 이니셜 라이저를 평가합니까?"라고 묻고 있습니다. –
네, {Source} 필드가 채워지지 않아 문자열을 노출하기 때문에 그렇습니다. – grmbl
'static' 클래스는'static' 클래스를 처음으로 초기화 할 때 값을 생성하므로'Source'를 변경하면 효과가 없습니다. 그러나 속성은 접근 할 때 새로운'string'에 대한 최신 값을 사용하여 새로운'string'을 초기화 할 것입니다. – juharr