我一直在這個問題現在要去幾天模型的一部分。我試圖使用Visual Studio 2010 MVC2 EF 6.0創建數據庫連接。我可以使用服務器瀏覽器連接到數據庫。
這是我迄今所做的:
- 創建的模型:ModelEntities.edmx(連接到SQL Server DB)
2.創建的表我一個型號「M試圖訪問:Table.cs(有所有的公共成員)
public class Quickfix
{
public int FIX_ID { get; set; }
public string NAME { get; set; }
public string TYPE { get; set; }
public string DESCRIPTION { get; set; }
}
創建了一個DAL文件夾並添加了我的上下文:(ModelEntitesContext.cs)
using ServiceDesk_Solution.Models;
命名空間ServiceDesk_Solution.DAL {
public class ModelEntitiesContext : DbContext { public ModelEntitiesContext() : base("ModelEntities") { } public DbSet<Quickfix> Quickfixs { get; set; } } }
我創造了我的視圖控制器(叫我控制器DBController.cs)
公共類DBController:控制器 { // // GET:/ DB/
<strike>ModelEntitiesContext db = new ModelEntitiesContext();</strike> ModelEntities db = new ModelEntities(); public ActionResult DB() { return View(db.Quickfix.ToList();); }
}
最後,我用我的模型
(DB.aspx)ModelEntities.Quickfix營造濃厚的看法,這是當我得到上下文錯誤(見錯誤和堆棧跟蹤波紋管)我的配置文件:
添加名稱= 「ModelEntities」 的connectionString =「元數據= RES:// /Models.CSCEntities.csdl | res:// /Models.ModelEntities.ssdl | RES://*/Models.ModelEntities.msl;提供商= System.Data.SqlClient的;提供程序連接字符串= "數據源= devsql;初始目錄=模型;堅持安全信息=真;用戶ID =用戶;密碼=密碼; multipleactiveresultsets = TRUE;應用程式=的EntityFramework " 「的providerName =」 System.Data.EntityClient」
沒有更多的錯誤
錯誤消息:
The entity type Quickfix is not part of the model for the current context.
說明:執行過程中發生了未處理的異常的當前網絡請求。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.InvalidOperationException:實體類型Quickfix不是當前上下文的模型的一部分。
Source Error:
Line 14: public ActionResult DB()
Line 15: {
Line 16: db.Quickfix.ToList();
Line 17: return View();
Line 18: }
Source File: ***_Solution\Controllers\DBController.cs Line: 16
Stack Trace:
[InvalidOperationException: The entity type Quickfix is not part of the model for the current context.]
System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType) +191
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +46
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +125
System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +33
System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +100
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +315
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
ServiceDesk_Solution.Controllers.DBController.DB() in ***_Solution\ServiceDesk_Solution\Controllers\DBController.cs:16
lambda_method(Closure , ControllerBase , Object[]) +96
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +409
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +52
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +127
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +305
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
System.Web.Mvc.Controller.ExecuteCore() +136
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +65
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8981789
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272