asp.net-mvc-3 – 首先是ASP.Net MVC 3 EF4.1代码 – 不支持每种
发布时间:2020-12-16 09:15:12 所属栏目:asp.Net 来源:网络整理
导读:我想使用可以单元测试的EF 4.1代码第一个模式.我按照 This Post的答案中说明的代码示例.但现在我收到一条错误,指出“不支持每种类型的多个对象集”.我也在使用最新的IoC结构图.我不知道如何解决这个问题. Multiple object sets per type are not supported.
我想使用可以单元测试的EF 4.1代码第一个模式.我按照
This Post的答案中说明的代码示例.但现在我收到一条错误,指出“不支持每种类型的多个对象集”.我也在使用最新的IoC结构图.我不知道如何解决这个问题.
Line 82: public virtual IEnumerable<T> FindAll() Line 83: { Line 84: return _dbSet.ToList(); Line 85: } Line 86: [InvalidOperationException: Multiple object sets per type are not supported. The object sets 'MemberTypes' and 'MemberTypes' can both contain instances of type 'SocialSite.Model.Entities.MemberType'.] System.Data.Entity.Internal.DbSetDiscoveryService.RegisterSets(DbModelBuilder modelBuilder) +336 System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder() +393 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +22 System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +117 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +407 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +17 System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62 System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +15 System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +40 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +315 System.Linq.Enumerable.ToList(IEnumerable`1 source) +58 SocialSite.Data.Repositories.Impl.Repository`1.FindAll() in D:Visual Studio 2010SocialSiteSocialSite.DataRepositoriesImplRepository.cs:84 SocialSite.Service.Impl.MemberTypesService.GetMemberTypes() in D:Visual Studio 2010SocialSiteSocialSite.ComponentsImplMemberTypesService.cs:23 SocialSite.Web.Areas.Admin.Controllers.MemberTypesController.ListMemberTypes() in D:Visual Studio 2010SocialSiteSocialSiteAreasAdminControllersMemberTypesController.cs:44 lambda_method(Closure,ControllerBase,Object[] ) +62 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object[] parameters) +17 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary`2 parameters) +208 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2 parameters) +27 System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter,ActionExecutingContext preContext,Func`1 continuation) +263 System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext,IList`1 filters,IDictionary`2 parameters) +191 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,String actionName) +343 System.Web.Mvc.Controller.ExecuteCore() +116 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50 System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862381 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) +184 不知道如何格式化堆栈跟踪比任何bertter. 这是有问题的模型. public class MemberType { [Key] public virtual int Id { get; set; } [StringLengthAttribute(65,ErrorMessage = "Maximum length 65 characters")] public virtual string Name { get; set; } public virtual string Description { get; set; } public virtual bool Registration { get; set; } public virtual bool Enabled { get; set; } [TimestampAttribute] public virtual byte[] Timestamp { get; set; } public virtual bool Activation { get; set; } public virtual Guid RoleId { get; set; } // TODO: this should be a complex type of aspnet_Role or atleaset a foriegn key public virtual bool Searchable { get; set; } public virtual ICollection<MemberTypeProfileFieldGroup> MemberTypeProfileFieldGroups { get; set; } } 解决方法
例外情况说你的DbContext(或者你的上下文中引用的某些类定义了DbSet< MemberType> MemberType两次.每种类型只能有一个定义的DbSet.你发布的代码与异常完全无关.当EF代码抛出异常时抛出异常首先探讨DbContext并从可用的DbSet创建模型元数据
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 如何显示如果绑定数据源是List Collection,则在
- asp.net-mvc-4 – .NET Web API Post Action返回空JSON
- 你如何正确使用UpdatePanel? (asp.net)
- ASP.NET MVC中数据注释的默认资源
- asp.net-mvc – IIS 7与IIS Express的路由错误,生成HTTP 40
- asp.net-mvc – 将ViewData传递给RenderPartial
- asp.net-mvc – 在ASP.NET MVC中使用线程设置当前文化
- asp.net-core-mvc – 如何在Asp.Net Core MVC 1.0(又名MVC
- asp.net-mvc – Asp.net MVC – 如何检查Ajax请求的会话过期
- 有哪些方法可以优化ASP.NET缓存的使用?
推荐文章
站长推荐
- asp.net-mvc-3 – 自定义错误适用于HttpCode 403
- asp.net-mvc-3 – Global.asax.cs在服务器上不可
- asp.net – 在IIS7中重启网站以“刷新”Castle W
- asp.net-mvc-3 – MVC3下拉列表未选择所选项目
- ASP.NET Web API控制器专用串行器
- asp.net core3.0 mvc 用 autofac
- asp.net – 是否有使用Markdown作为编辑器的WIKI
- asp.net-mvc-4 – 无法解析类型名称:Glass.Mapp
- asp.net – 如何使用DataPager与服务器端寻呼?
- asp.net – 在项目之间共享aspx页面
热点阅读