小编noc*_*ock的帖子

Global.asax无法找到代码隐藏类

当我尝试运行我继承的Web应用程序时,我不断收到此错误.它是在2010年为C#3.5编写的并使用了Mvc 2.我已经安装了必要的库,但是我收到了这个错误.

错误1无法加载类型'AdminConsole.MvcApplication'.C:\ path\to\my\app\Global.asax 1

Global.asax.cs看起来像这样:

using System.Web.Mvc;
using System.Web.Routing;

namespace AdminConsole
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}.aspx/{action}/{id}", // URL with parameters
                new { controller = "Entitlement", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

而Global.asax看起来像这样: <%@ Application Inherits="AdminConsole.MvcApplication" …

c# asp.net asp.net-mvc visual-studio asp.net-mvc-2

5
推荐指数
2
解决办法
2万
查看次数

LINQ to SQL布尔值的评估顺序

我有以下代码,当我向PerformQuery方法提供null参数时,它生成一个空引用异常.

public class MyObject
{
    public Guid Guid { get; private set; }
}
public class TableObject
{
    // This is a Guid stored as a string
    public string Hash { get; set; }
}
public DataContext context;
public TableObject PerformQuery(MyObject obj)
{
    return context.TableObjects.FirstOrDefault(tableObject =>
        obj != null &&
            // Why is this side of the condition being evaluated if obj is null?
        string.Equals(obj.Guid.ToString(), tableObject.Hash));
}
Run Code Online (Sandbox Code Playgroud)

我确定它TableObject不是空的.怎么可能呢?并且它的属性Hash不可为空,所以它也不应该为空(尽管我已经检查了null并没有改进).

我通过在执行查询之前计算我正在搜索的Guid字符串自己解决了这个问题,但我很好奇为什么LINQ继续评估条件,即使obj是null.这是因为LINQ to SQL优化,布尔值的评估顺序与传统if …

c# sql linq linq-to-sql

2
推荐指数
1
解决办法
244
查看次数