:私は財産としてクエリを公開するとき補間された文字列はいつ評価されますか?私は次のコードしている
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
}
だけ時間が満たされているです。 (QUERY_003)
フィールドとして公開されていると動作しません。 (QUERY_001、QUERY_002)
誰でも理由を説明できますか? の静的性のために(それが単語かどうかわからない)?これは、実行時に行うのSQL :)
本当に、文字列補間はここでは赤いニシンです。あなたは効果的に "いつフィールドイニシャライザが評価されるのですか?" –
はい{フィールド}が入力されていないため、文字列を公開しているためです。 – grmbl
'static'なのは 'static'クラスを初めて初期化するときに値を生成することを意味し、' Source'を変更しても効果がないからです。しかし、このプロパティは、新しい 'string'をアクセスしたときに' Source'の最新の値を使用して初期化します。 – juharr