您好,我有一个应用程序在azure上发布。当我尝试访问BookDetail页面时,出现InvalidColumn "Borrowed"错误。在具有“电话号码”和“密码”列的UserDetail页面上,也会发生同样的事情。

这是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服务上使用新数据库时,就会出现此问题。
您的帮助将不胜感激。

最佳答案

今天下午我遇到了同样的问题。在花费了大约2个小时的重新部署并尝试新的迁移之后。开启和关闭App Service对我来说是成功的窍门。

c# - 在Azure上发布时列名无效-LMLPHP

关于c# - 在Azure上发布时列名无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30493744/

10-16 14:24
查看更多