I have DataContext as a connection to my database and also use pre-compiled queries (CompiledQuery). Here is my code:
public static RichTextValue GetRichTextValue(this DataManager db, string key, string lang = LobbyHelper.DefaultLanguage) {
return CompiledQueryExtensions.RichTextValueByKeyAndLang(db, key, lang);//NullReferenceException is thrown here
}
where DataManager extends DataContext. DataManager static instance is shared within the whole project.
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));
}
What most confuses me is that when page is requested ordinarily (via browser url) all is fine, but when I use ajax to request a PartialView and put it on the page, I get the excetpion.
Please assist