Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid column name when published on azure

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.

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;
    }

Here is my model

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; }

}

}

And here is my context file

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; }

}
}

Stack Trace

[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

This problem appeared when i published my application to azure and used a new database on the azure service. Your help would be appreciated.

like image 563
Pavel Kašelják Avatar asked Nov 09 '22 12:11

Pavel Kašelják


1 Answers

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.

enter image description here

like image 70
Trevi Awater Avatar answered Nov 14 '22 21:11

Trevi Awater