在Azure上发布时列名无效 [英] Invalid column name when published on azure
问题描述
你好,我有一个在azure上发布的应用程序.当我尝试访问BookDetail页面时,出现InvalidColumn "Borrowed"
错误.在UserDetail页面的电话号码"和密码"列中也会发生同样的事情.
Hello I have a application published on azure. When I try to acces BookDetail page I get a InvalidColumn "Borrowed"
error. The same thing happens on a UserDetail page with column PhoneNumber and Password.
这是BookDetail的获取方法
Here is the BookDetail getmethod
public IQueryable<Book> GetBook([QueryString("BookID")] int? BookID)
{
var _db = new WebApplication1.Models.LibraryContext();
IQueryable<Book> query = _db.Books;
if (BookID.HasValue && BookID > 0)
{
query = query.Where(p => p.BookID == BookID);
}
else
{
query = null;
}
if (query == null || query.Count() == 0)
{
inputUserBorrow.Visible = false;
inputUserBorrowButton.Visible = false;
}
return query;
}
这是我的模特
namespace WebApplication1.Models
{
public class LibUser
{
[Key]
public int UserID { get; set; }
[Required, StringLength(50), Display(Name = "First Name")]
public string UserFirstName { get; set; }
[Required, StringLength(50), Display(Name = "Last Name")]
public string UserLastName { get; set; }
[Required, StringLength(100), Display(Name = "Street"), DataType(DataType.Text)]
public string Adress { get; set; }
[Required, StringLength(20), Display(Name = "Phone Number"), DataType(DataType.Text)]
public string PhoneNumber { get; set; }
public string Password { get; set; }
}
public class Book
{
[Key]
public int BookID { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public DateTime Published { get; set; }
public bool Borrowed { get; set; }
public Book() {
Borrowed = false;
}
}
public class Borrowed
{
[Key]
public int BorrowID { get; set; }
public int UserID { get; set; }
public int BookID { get; set; }
public string BookTitle { get; set; }
public DateTime Due { get; set; }
}
}
这是我的上下文文件
namespace WebApplication1.Models
{
public class LibraryContext : DbContext
{
public LibraryContext()
: base("LibraryContext")
{
}
public DbSet<LibUser> LibUsers { get; set; }
public DbSet<Book> Books { get; set; }
public DbSet<Borrowed> Borrows { get; set; }
}
}
堆栈跟踪
[SqlException (0x80131904): Invalid column name 'Borrowed'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1787814
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341674
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1693
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
System.Data.SqlClient.SqlDataReader.get_MetaData() +90
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +377
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1421
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +137
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c) +9
System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +72 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) +356
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) +166
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +37
当我将应用程序发布到azure并在azure服务上使用新数据库时,出现了此问题. 您的帮助将不胜感激.
This problem appeared when i published my application to azure and used a new database on the azure service. Your help would be appreciated.
推荐答案
今天下午我遇到了同样的问题.经过大约2个小时的重新部署并尝试了新的迁移.开启和关闭App Service对我来说是成功的秘诀.
I had the same issue this afternoon. After spending about 2 hours of redeploying and trying new migrations. Turning the App Service off and on did the trick for me.
这篇关于在Azure上发布时列名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!