问题描述
请各位大大指点一下关于LINQ动态数据网站的问题,谢谢代码如下Default.aspx.csusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Linq;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Xml.Linq;usingSystem.Web.DynamicData;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){System.Collections.IListvisibleTables=MetaModel.Default.VisibleTables;if(visibleTables.Count==0){thrownewInvalidOperationException("没有可访问的表。请确保至少在Global.asax中注册了一个数据模型并启用了支架,或者实现自定义页。");}Menu1.DataSource=visibleTables;Menu1.DataBind();}}
Global.asax<%@ApplicationLanguage="C#"%><%@ImportNamespace="System.Web.Routing"%><%@ImportNamespace="System.Web.DynamicData"%><scriptRunAt="server">publicstaticvoidRegisterRoutes(RouteCollectionroutes){MetaModelmodel=newMetaModel();model.RegisterContext(typeof(DataClassesDataContext),newContextConfiguration(){ScaffoldAllTables=true});routes.Add(newDynamicDataRoute("{table}/{action}.aspx"){Constraints=newRouteValueDictionary(new{action="List|Details|Edit|Insert"}),Model=model});}voidApplication_Start(objectsender,EventArgse){RegisterRoutes(RouteTable.Routes);}</script>
DataClasses.designer.cs#pragmawarningdisable1591usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Data.Linq;usingSystem.Data.Linq.Mapping;usingSystem.Linq;usingSystem.Linq.Expressions;usingSystem.Reflection;publicpartialclassDataClassesDataContext:System.Data.Linq.DataContext{privatestaticSystem.Data.Linq.Mapping.MappingSourcemappingSource=newAttributeMappingSource();#region可扩展性方法定义partialvoidOnCreated();#endregionpublicDataClassesDataContext(stringconnection):base(connection,mappingSource){OnCreated();}publicDataClassesDataContext(System.Data.IDbConnectionconnection):base(connection,mappingSource){OnCreated();}publicDataClassesDataContext(stringconnection,System.Data.Linq.Mapping.MappingSourcemappingSource):base(connection,mappingSource){OnCreated();}publicDataClassesDataContext(System.Data.IDbConnectionconnection,System.Data.Linq.Mapping.MappingSourcemappingSource):base(connection,mappingSource){OnCreated();}}#pragmawarningrestore1591
生成网站后提示错误如下“/”应用程序中的服务器错误。没有为该对象定义无参数的构造函数。说明:执行当前Web请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息:System.MissingMethodException:没有为该对象定义无参数的构造函数。源错误:行6:publicstaticvoidRegisterRoutes(RouteCollectionroutes){行7:MetaModelmodel=newMetaModel();行8:model.RegisterContext(typeof(DataClassesDataContext),newContextConfiguration(){ScaffoldAllTables=true});行9:routes.Add(newDynamicDataRoute("{table}/{action}.aspx"){行10:Constraints=newRouteValueDictionary(new{action="List|Details|Edit|Insert"}),源文件:e:tsjWEBGlobal.asax行:8堆栈跟踪:[MissingMethodException:没有为该对象定义无参数的构造函数。]System.RuntimeTypeHandle.CreateInstance(RuntimeTypetype,BooleanpublicOnly,BooleannoCheck,Boolean&canBeCached,RuntimeMethodHandle&ctor,Boolean&bNeedSecurityCheck)+0System.RuntimeType.CreateInstanceSlow(BooleanpublicOnly,BooleanfillCache)+86System.RuntimeType.CreateInstanceImpl(BooleanpublicOnly,BooleanskipVisibilityChecks,BooleanfillCache)+230System.Activator.CreateInstance(Typetype,BooleannonPublic)+67System.Web.DynamicData.<>c__DisplayClass1.<RegisterContext>b__0()+9System.Web.DynamicData.MetaModel.RegisterContext(Func`1contextFactory,ContextConfigurationconfiguration)+336System.Web.DynamicData.MetaModel.RegisterContext(TypecontextType,ContextConfigurationconfiguration)+79ASP.global_asax.RegisterRoutes(RouteCollectionroutes)ine:tsjWEBGlobal.asax:8ASP.global_asax.Application_Start(Objectsender,EventArgse)ine:tsjWEBGlobal.asax:31[HttpException(0x80004005):没有为该对象定义无参数的构造函数。]System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContextcontext,HttpApplicationapp)+2727622System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtrappContext,HttpContextcontext,MethodInfo[]handlers)+128System.Web.HttpApplication.InitSpecial(HttpApplicationStatestate,MethodInfo[]handlers,IntPtrappContext,HttpContextcontext)+188System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtrappContext,HttpContextcontext)+295System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtrappContext,HttpContextcontext)+56System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtrappContext)+231[HttpException(0x80004005):没有为该对象定义无参数的构造函数。]System.Web.HttpRuntime.FirstRequestInit(HttpContextcontext)+8923723System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContextcontext)+85System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequestwr,HttpContextcontext)+333
解决方案
本帖最后由 hentaidd 于 2014-10-08 20:46:41 编辑
解决方案二:
这个类ContextConfiguration没有无参的构造函数吧?
解决方案三:
添加了还是提示没有无参数的构造函数publicclassContextConfiguration{publicContextConfiguration(){/*这是一个无参的构造函数*/}}错误列表显示如下错误4未知的服务器标记“asp:DynamicValidator”。
解决方案四:
引用2楼hentaidd的回复:
添加了还是提示没有无参数的构造函数publicclassContextConfiguration{publicContextConfiguration(){/*这是一个无参的构造函数*/}}错误列表显示如下错误4未知的服务器标记“asp:DynamicValidator”。
要引用System.Web.DynamicData
解决方案五:
无参构造是指DataClassesDataContext