Entity Framework - Invalid Column Name '*_ID"

后端 未结 15 1599
长发绾君心
长发绾君心 2020-11-29 21:30

I\'ve narrowed this down to some issue between Code First and Database first EF, but I\'m not sure how to fix it. I\'ll try to be as clear as I can, but I honestly am missin

15条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 21:48

    Assumptions:

    • Table
    • OtherTable
    • OtherTable_ID

    Now choose one of this ways:


    A)

    Remove ICollection

    If you have some error related to OtherTable_ID when you are retrieving Table, go to your OtherTable model and make sure you don't have an ICollection

    in there. Without a relationship defined, the framework will auto-assume that you must have a FK to OtherTable and create these extra properties in the generated SQL.

    All Credit of this answer is belongs to @LUKE. The above answer is his comment under @drewid answer. I think his comment is so clean then i rewrote it as an answer.


    B)

    • Add OtherTableId to Table

    and

    • Define OtherTableId in the Table in database

    提交回复
    热议问题