我有一個MySql和實體框架代碼優先的問題。MySql和實體框架代碼優先
public class EntityContext : DbContext
{
public DbSet<Pessoa> Pessoas { get; set; }
}
我的類別::
[Table("pessoa")]
public class Pessoa
{
[Key]
[Column("Id")]
public int Id { get; set; }
[Column("Nome")]
public string Nome { get; set; }
}
我的控制器
public EntityContext db = new EntityContext();
public ActionResult Index()
{
List<Pessoa> pessoas = db.Pessoas.ToList(); // here is the error
return View(pessoas);
}
在web.config.xml
<add name="EntityContext" connectionString="Server=127.0.0.1; port=8080 Database=simple_crud; Uid=root; Pwd=;" providerName="MySql.Data.MySqlClient" />
我的上下文
我的連接字符串3210
所以,當我按F5時,我得到了這個:「輸入字符串格式不正確」。
我很想念?
UPDATE
堆棧跟蹤:
[出現FormatException:輸入字符串的不正確的格式]
System.Number.StringToNumber(字符串str,的NumberStyles選項, NumberBuffer & NumberFormatInfo info,Boolean parseDecimal) +9591147 System.Number.ParseUInt32(String value,NumberStyles options,NumberFormatInfo numfmt)+119
System.String.System.IConvertible.ToUInt32(的IFormatProvider提供商) 46 System.Convert.ChangeType(對象值,類型conversionType,的IFormatProvider提供商)9509065
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.ChangeType(對象 值, T型)240
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.SetValue(字符串 關鍵字,對象的值)399
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.set_Item(字符串 關鍵字,對象的值)54
系統.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)+127
MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(字符串 值)289
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(字符串 名)409
System.Data.Entity.Internal.LazyInternalConnection.Initialize ()49
System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel() 10 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 265 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(類型 entityType)+17
System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +62
1.GetEnumerator() 15
System.Data.Entity.Internal.Linq.InternalSet
System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +40 System.Collections.Generic.List
1..ctor(IEnumerable的源)58 SimpleMysqlCrud.Controllers.PessoaController.Index()在 F:\用戶\ pablo.rocha.fti \文件\ Visual Studio 2010 \ Projects \ SimpleMysqlCrud \ SimpleMysqlCrud \ Controllers \ PessoaController。CS:16 lambda_method(封閉,ControllerBase,對象[])62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,對象[]參數)17
System.Web.Mvc.ReflectedActionDescriptor.Execute (ControllerContext controllerContext,IDictionary parameters)+27
System.Web.Mvc。 <> C_ DisplayClass15.b _12() 55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter 濾波器,ActionExecutingContext preContext,函數功能1 continuation) +263
1個濾波器,ActionDescriptor actionDescriptor, IDictionary的
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList2 parameters) +191
1.b__7(IAsyncResult的 ) 12 System.Web.Mvc.Async.WrappedAsyncResult`1.End()62 System.Web.Mvc。<> c^ _DisplayClasse.b_ d()50
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
System.Web.Mvc.SecurityUtil.b _0(動作f)+7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(動作動作) +22 Sys tem.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult的asyncResult)60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult的 結果)9
System.Web.CallHandlerExecutionStep.System.Web .HttpApplication.IExecutionStep.Execute() 8970141 System.Web.HttpApplication.ExecuteStep(IExecutionStep一步,布爾& completedSynchronously)184
哪條線是個例外呢? –
您忘記了在** port = 8080之後添加分號**否? –
@AndreyVoloshin,請舉個例子。 – Pablo