データベースへの接続として DataContext があり、コンパイル済みのクエリ (CompiledQuery) も使用します。これが私のコードです:
public static RichTextValue GetRichTextValue(this DataManager db, string key, string lang = LobbyHelper.DefaultLanguage) {
return CompiledQueryExtensions.RichTextValueByKeyAndLang(db, key, lang);//NullReferenceException is thrown here
}
ここで、DataManager は DataContext を拡張します。DataManager 静的インスタンスはプロジェクト全体で共有されます。
public static class CompiledQueryExtensions
{
public static Func<DataManager, string, string, RichTextValue> RichTextValueByKeyAndLang =
CompiledQuery.Compile((DataManager db, string key, string lang) =>
db.RichTextValues.SingleOrDefault(x => !x.Deleted && !x.RichText.Deleted && !x.Language.Deleted
&& x.RichText.Key == key && x.Language.Code == lang));
}
私を最も混乱させているのは、ページが通常 (ブラウザーの URL を介して) 要求された場合はすべて問題ないのですが、ajax を使用して PartialView を要求し、それをページに配置すると、例外が発生することです。
手伝ってください