EF CodeFirst: Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong

前端 未结 10 2234
Happy的楠姐
Happy的楠姐 2020-12-13 23:35

I\'ve a table named EducationTypes and an Entity named EducationType, I renamed one of entity properties, now I\'m frequently getting Either

相关标签:
10条回答
  • 2020-12-14 00:10

    I got this with Entity Framework 6 when trying to rename a foreign key in my migrations script using the Sql(" ... ") method. The workaround I had was to use square brackets around the name:

    i.e. changing this:

    sp_rename 'FK_dbo.tablename_dbo.othertablename_fieldname', 'FK_dbo.tablename_dbo.othertablenewname_fieldnewname', 'object'
    

    ...to this:

    sp_rename '[FK_dbo.tablename_dbo.othertablename_fieldname]', 'FK_dbo.tablename_dbo.othertablenewname_fieldnewname', 'object'
    

    SQL Server is then able to find the foreign key.

    0 讨论(0)
  • 2020-12-14 00:11

    Actually this error also happens when you just deleted the database, and your context does not realize that your database is not there.

    I recreated the database, and now the error was resolved.

    P.S. make sure you check database is still there when you try to run the update-database

    0 讨论(0)
  • 2020-12-14 00:12

    If you're using Code First and have (an) existing Migration script(s) and are trying to overwrite a change (i.e. renaming a column) that has since been deleted, then you'll get that error output. Simplest way is to delete the migration script, Add-Migration via NuGet, and then update the database.

    0 讨论(0)
  • 2020-12-14 00:12

    This is because of name Conflict of Class (Model) names with other reserved or generated ones, when auto creates the tables and ... .

    Considering that EF Code First creates the intervene tables to relate 2 or more tables using name of tables for derived intervene table, so when you use a class name that employs a name like the intervene tables, we'll get such this ambiguous error.

    For example if you have a Question class which has an Answer navigation property the internal model metadata will contain a reference called QUESTION_ANSWER

    To solve this, try to change the class names (used for generating tables) and ensure their uniqueness.

    0 讨论(0)
提交回复
热议问题