[英]When are interpolated string evaluated?
我有以下代碼:
internal class Constants
{
internal static string Source { get; set; }
#region EvaluationRepository
internal static string QUERY_001 = $@"
select
e.*
from {Source} e
where
e.id = @Id
";
internal static string QUERY_002 = $@"
select
e.*
from {Source} e
where
e.statusid=@StatusId
and e.begindate >= @FromDate
and e.enddate <= @ToDate
";
internal static string QUERY_003
{
get
{
return $@"
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的逐字內插噪聲:)
它在運行時完成。 與使用string.Format
等效(向下到生成的IL)。
字段未正確填充的原因是因為Source
最初執行時(初始化靜態類時)為空。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.