locked
EF invalid column name "PayAmount" - and ongoing EF misery RRS feed

  • Question

  • User379720387 posted

    I have added a single column called "PayAmount" to an existing table (Transactions) with datatype money Allow Nulls to my local and remote dbs.

    Everything the same.

    On the local machine in the EF diagram I selected "Update Model from Database". Saved the changes and did a Build

    That was all OK.

    Published the changes to these EF related files to Azure.

    Locally everything works as intended but on the remote I am getting a complaint about invalid column name


    Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'PayAmount'.

    Source Error: 

    Line 42:     var records = (from t in theProvider.Transactions
    Line 43:                    where t.ProviderId == providerid
    Line 44:                    && t.ClientId == clientid

    I have verified the new column is indeed in the live db.
    Looking for suggestions as to what can cause this. That is my first question.

    My second question is related to my normal solution in this case.  I would typically wipe the entire EF Model, and start from scratch. It is a very time consuming solution as there are many custom Navigation Properties and I always seem to mess up the name of the model so I have to go through the code and fix things. Done this now probably 8 - 10 times and really hate it.

    I easily loose half a day. Is there a better way to recover from these EF issues?

    Wednesday, December 6, 2017 7:27 PM

All replies

  • User379720387 posted

    I received a friendly suggestion for a troubleshooting step to test if the column could be gotten with straight SQL. 

    Well, I could not.  Find out I had added the new column in the old db, while my connection string was point to the new db.

    Shame on me.

    Still would like to hear from those skilled in the art of EF what you do when the model gets dirty.

    Wednesday, December 6, 2017 10:57 PM
  • User1120430333 posted

    Still would like to hear from those skilled in the art of EF what you do when the model gets dirty.

    What do you mean by this?

    Thursday, December 7, 2017 8:08 AM
  • User1400794712 posted

    Hi wavemaster,

    When I meet problem during using EF, the first thing I will do is to check the error information. Usually, the error information will give us useful tips. Then, if you are not familiar with this error information, you can search it on the Internet.

    If I still can't solve this error, I will use breakpoint and watch tool in VS to debug my project. Then using F10 to run the project step by step. I think this way is really useful. Hope my idea will help you.


    Best Regards,
    Daisy

    Thursday, December 7, 2017 10:38 AM
  • User379720387 posted

    @X.Daisy

    my challenge was that it worked local, but not live.

    Thursday, December 7, 2017 2:40 PM
  • User379720387 posted

    @DA924

    I dread making changes to the db because redoing the model from the db, in my experience, is not fool proof.

    Sometimes I end up with a long list of errors, worded in such a fashion that it is difficult for me to figure out what these errors mean.

    Thursday, December 7, 2017 2:44 PM
  • User1120430333 posted

    @DA924

    I dread making changes to the db because redoing the model from the db, in my experience, is not fool proof.

    Sometimes I end up with a long list of errors, worded in such a fashion that it is difficult for me to figure out what these errors mean.

    Yeah, if using Code first, I could see that being a problem. You don't face the issues using DB first, because you can update the model from the database and validated the model.

    Thursday, December 7, 2017 8:27 PM
  • User379720387 posted

    I only have data first code.

    My experience with EF is not good as far as making changes to the db and it blowing up the model.edmx

    Tuesday, December 31, 2019 2:30 PM