ASP.NET .resx 中的内容是“静态的”吗?
在 ASP.NET 中,我是否可以将参数化的 sql 查询存储在 .resx 文件中,并且在多个用户同时登录时不会遇到麻烦?
例如,我将把我的用户详细信息查询放在 .resx 文件中:
SELECT * FROM User WHERE UserId = @UserId
ASP.NET 将如何处理它?像“会话”(不同的用户有不同的结果)还是像“公共静态”/“应用程序”?
In ASP.NET, can I store parameterized sql queries in .resx files and not get into trouble when I have several users logged in at the same time?
For example, i'll put my user detail query in a .resx file:
SELECT * FROM User WHERE UserId = @UserId
How will ASP.NET treat it? Like a "Session" (different users have different results) or like a "public static"/"Application" ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
资源文件通常用于存储特定于语言的字符串,而不是用于存储要执行的查询,我想您可以做到这一点,但为什么呢?您的问题似乎缺少了一个部分,是什么推动了您的这一要求?
编辑:如果您只能访问 mysql,为什么不使用 ORM 工具,例如 subsonic 或 nhibernate
resource files are typically for storing language specific strings, not for storing queries to execute, I guess you could do it, but why? It seems that there is a piece missing from your question, what is driving this requirement on your end?
EDIT: If you only have access to mysql, why not use an ORM tool like subsonic or nhibernate
我不想过多评论这是否是一个好主意,但基本上,您不只是存储字符串吗?当您使用参数化查询时,至少在 ADO.NET 中,您将在运行查询之前添加参数。
I'm not intending to comment so much on whether this is a good idea or not, but basically, aren't you just storing strings? When you use a parameterized query, in ADO.NET at least, you will add the parameters before running the query.
@UserID
必须来自您的代码,该代码需要以某种方式从登录用户(或您的应用程序的工作方式)获取值,因此字符串的静态与否并不重要是。也就是说,如果可能的话,您应该使用存储过程而不是这个。
@UserID
would have to come from your code, which needs to somehow obtain the value from the logged-in user (or however your app works), so it doesn't matter how static or not the strings are.That said, you should be using stored procedures if possible instead of this.