3
我的许多应用程序都使用complied查询来检索数据。在这些查询中,我经常会引用当前用户。我注意到,如果用户B在另一个用户A之后登录,则用户B将看到用户A的信息。编译查询缓存?
我有疑问很像这一切都通过了申请
public static Func<DataContext, MyRecord> CurrentUserRecords =
CompiledQuery.Compile<DataContext, MyRecord>(
(DataContext db) =>
(from r in db.MyRecords
where
r.User == User.Current
select r).SingleOrDefault());
User.Current
是取决于谁在登录改变的静态属性。
public static User Current
{
get { return MyBase<User>.Get((int)(HttpContext.Current.Session["CurrentUserID"] ?? 0)); }
}
当我登录首次使用用户A,上面编译的查询返回用户A的记录。因此,User.Current也会返回对用户A的适当引用。但是,当我以用户B登录时,尽管User.Current正在返回对用户B的引用,但上述编译后的查询仍会返回用户A的记录。
我跑了SQL Server的Profiler,并注意到编译查询执行时生成的TSQL引用用户A的ID两次。
所以我的问题是这样的:
不要编译查询莫名其妙缓存?
如果是这样,那有什么寿命,我可以控制它吗?
是否在ASP.net应用程序的编译查询不良设计中引用“当前用户”?
谢谢大家!
我很害怕这个。我目前已经掌握了CompliledQuery.compile重载将允许使用的参数数量。我确实发现这个虽然http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/f1fc5570-be6d-4d7f-b94f-aa5b6e9922cf/ – 2009-06-17 13:05:25