2015-05-10 42 views
1

當我從Visual Studio運行它時,我的項目web api與EF6和MySQL數據庫運行正常,但是當我發佈到本地IIS服務器時,它返回以下異常。在使用MySQL數據庫生成模型時檢測到EF6驗證錯誤

 
System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation: 

DataBaseLayer.Banco: : EntityType 'Banco' has no key defined. Define the key for this EntityType. 
[...] 
Bancos: EntityType: EntitySet 'Bancos' is based on type 'Banco' that has no keys defined. 
[...] 

    em System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate() 
    em System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) 
    em System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) 
    em System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) 
    em System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) 
    em System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 
    em System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) 
    em System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() 
    em System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() 
    em System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() 
    em System.Data.Entity.QueryableExtensions.SingleOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken) 
    em System.Data.Entity.QueryableExtensions.SingleOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate) 
    em DataBaseLayer.UtilizadorDB.d__15.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em BusinessLayer.UtilizadorBL.d__d.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em ColetorDividas.Providers.UserStoreService.d__0.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em Microsoft.AspNet.Identity.TaskExtensions.CultureAwaiter`1.GetResult() 
    em Microsoft.AspNet.Identity.UserManager`2.d__12.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em ColetorDividas.Providers.ApplicationOAuthProvider.d__0.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__3f.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) 
    em Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__22.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) 
    em Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__0.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.d__0.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.d__5.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    em Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.d__2.MoveNext() 
--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida --- 
    em Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) 
    em Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) 
    em System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 
    em System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 

我已經與數據註解這樣映射代碼的關鍵在於:

public class Banco 
{ 
    [Key] 
    [Display(Name = ConstResources.CodigoBanco, ResourceType = typeof(ResourcePT))] 
    public int CodigoBanco { get; set; } 

    [Display(Name = ConstResources.Designacao, ResourceType = typeof(ResourcePT))] 
    [Required(ErrorMessageResourceName = ConstResources.CampoObrigatorio, ErrorMessageResourceType = typeof(ResourcePT))] 
    [StringLength(250, ErrorMessageResourceName = ConstResources.CampoTamanho, ErrorMessageResourceType = typeof(ResourcePT))] 
    public string Designacao { get; set; } 

    public virtual ICollection<BancoPag> BancosPagamentos { get; set; } 
} 

任何想法如何解決這個問題。

+0

對此問題沒有想法:( – fmalh3iro

回答

0

IIS服務器無法識別模型中的數據註釋,它僅適用於Fluent API。

爲什麼IIS服務器不能識別數據註釋?

相關問題