我已经编写了3个ASP.net MVC Web应用程序,并且所有这些应用程序都部署在我的ISP的共享主机服务器上.
所有3个应用程序在配置和设置方面都非常相似.第一个应用程序部署到与第二个和第三个不同的服务器.第一个应用程序没有给我任何错误.
第二个和第三个应用程序稍微吐出以下SecurityException :随机:
替代文字http://i46.tinypic.com/24p9pac.jpg
例外文字:
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.
Source Error:
An unhandled exception was generated during the execution of the current web request. …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc log4net securityexception shared-hosting
我有2个相关的Linq to SQL问题.请参阅下面的图片,看看我的模型是什么样的.
问题1
我想知道如何User.AddedByUser在我的User 类/表上加载字段.该字段由字段上的关系生成User.AddedByUserId.该表是自引用的,我试图弄清楚如何让Linq to SQL User.AddedByUser急切地加载属性,即无论何时User加载/获取任何实体,它还必须获取User.AddedByUser和User.ChangedByUser.但是,据我所知,这可能会成为一个递归问题......
更新1.1:
我试过使用DataLoadOptions如下:
var options = new DataLoadOptions();
options.LoadWith<User>(u => u.ChangedByUser);
options.LoadWith<User>(u => u.AddedByUser);
db = new ModelDataContext(connectionString);
db.LoadOptions = options;
Run Code Online (Sandbox Code Playgroud)
但这不起作用,我在第2行得到以下异常:
System.InvalidOperationException occurred
Message="Cycles not allowed in LoadOptions LoadWith type graph."
Source="System.Data.Linq"
StackTrace:
at System.Data.Linq.DataLoadOptions.ValidateTypeGraphAcyclic()
at System.Data.Linq.DataLoadOptions.Preload(MemberInfo association)
at System.Data.Linq.DataLoadOptions.LoadWith[T](Expression`1 expression)
at i3t.KpCosting.Service.Library.Repositories.UserRepository..ctor(String connectionString) in C:\Development\KP Costing\Trunk\Code\i3t.KpCosting.Service.Library\Repositories\UserRepository.cs:line 15
InnerException:
Run Code Online (Sandbox Code Playgroud)
异常是不言自明的 - 对象图不允许是循环的.另外,假设第2行没有抛出异常,我很确定第3行会,因为它们是重复键.
更新1.2:
以下内容也不起作用(不与上面的Update 1.1结合使用):
var query = from u …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的网站创建一个菜单.它需要满足以下要求
目前,我有一个简单的示例运行,但我不知道如何集成缓存.我想我可能需要在整个工作方式上进行修改.这里是:
我有一个ProductMenuAttribute,它从数据库中提取数据,并将其存储在ViewData中:
public class ProductMenuAttribute: FilterAttribute, IActionFilter
{
#region IActionFilter Members
public void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext != null)
{
var context = filterContext.Result as ViewResult;
if (context != null)
{
ProductsRepository repository = new ProductsRepository(Properties.Settings.Default.SqlConnectionString);
context.ViewData.Add("ProductsList", repository.GetAllProductRanges());
}
}
}
public void OnActionExecuting(ActionExecutingContext filterContext)
{
}
#endregion
}
Run Code Online (Sandbox Code Playgroud)
在我的Site.master中,我从ViewData中提取数据并使用它来呈现我的菜单.这是我的无序菜单列表中的一个小片段,它使用CSS进行样式设置.这是代码:
<li>
<%= Html.ActionLink("Products", "Index", "Products")%>
<% IQueryable<ProductRange> productRanges = ViewData["ProductsList"] as IQueryable<ProductRange>; %>
<% if (productRanges != null) …Run Code Online (Sandbox Code Playgroud) 我正在开始一个新项目,我正在考虑在我的SQL Server 2005数据库中使用别名数据类型,用于公共表列.例如,我将定义一个别名数据类型来保存对象的名称,如下所示:
CREATE TYPE adt_Name FROM varchar(100)not null
然后使用它来定义表列,确保我的所有列共享完全相同的定义(长度,可空性,精度等).
我有以下SQL表:
CREATE TABLE [dbo].[Test](
[TestID] [int] NOT NULL,
[TestNum] [int] NULL,
[TestReason] [varchar](50) NULL
)
Run Code Online (Sandbox Code Playgroud)
所以TestNum是一个允许NULL值的INT,我在表中插入了大量的数据,其中一些行包含TestNum的NULL值
如果我然后运行以下查询
select *
from Test
where TestNum != 123
Run Code Online (Sandbox Code Playgroud)
查询aboe不返回任何具有NULL值的行.我希望它返回所有行除了那些值为123的行.
为什么是这样?
我在MS-SQL 2000数据库上运行此查询,导入到MS SQL 2005.这有什么影响吗?或者这是所有版本的MS SQL Server的行为标准?
我需要Visual Studio 搜索和替换功能的正则表达式,如下所示:
搜索以下术语:sectorkey in(
在上述3个搜索项中的每一个之间可能存在多个空格,或甚至多个换行符/回车符.
搜索条件正在寻找那些硬编码的SQL内SectorKey值SQL语句中声明.这些需要用SQL连接语句替换 - 这将手动完成.
我有一个名为Periods的表,看起来像这样
PeriodID | PeriodYear | PeriodQuarter
7 | 2009 | 1
8 | 2009 | 2
9 | 2009 | 3
10 | 2009 | 4
11 | 2010 | 1
12 | 2010 | 2
表中的每一行代表一年中四个季度中的一个(如3个月的学期).例如,第一行代表2009年第1期(即日期范围2009年1月1日至2009年3月31日).
现在,我需要编写一个查询,从上表中选择行/句点,其中句点出现在2个日期范围之间,如下面的伪代码所示.
select *
from Periods
where Period is between @startDate and @endDate
Run Code Online (Sandbox Code Playgroud)
该查询将在名为dbo.GetPeriodsFromDateRange的表值函数内使用,而@startDate和@endDate是函数的参数.
我陷入困境,无法弄清楚如何做到这一点.请帮忙.这适用于T-SQL(MS SQL Server 2000/2005)
我有以下SQL查询:
select AuditStatusId
from dbo.ABC_AuditStatus
where coalesce(AuditFrequency, 0) <> 0
Run Code Online (Sandbox Code Playgroud)
我正在努力理解它.它看起来很简单,我知道coalesce运算符的作用(或多或少),但似乎没有得到意义.
除了上面的查询之外,如果不知道任何其他信息,您认为这意味着什么?
是否可以在2个表之间进行CROSS JOIN,然后将LEFT JOIN连接到第3个表,然后可能还有更多的左连接?我使用的是SQL Server 2000/2005.
我正在运行以下查询,这是非常简单的转发IMO,但我收到一个错误.
select P.PeriodID,
P.PeriodQuarter,
P.PeriodYear,
M.Name,
M.AuditTypeId,
A.AuditId
from Period P, Member M
LEFT JOIN Audits A
ON P.PeriodId = A.PeriodId
WHERE
P.PeriodID > 29 AND P.PeriodID < 38
AND M.AuditTypeId in (1,2,3,4)
order by M.Name
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
消息4104,级别16,状态1,行1无法绑定多部分标识符"P.PeriodId".
如果我删除LEFT JOIN,查询将起作用.但是,我需要LEFT JOIN,因为我需要从其他表中提取更多信息.
我究竟做错了什么?有更好的方法吗?