Unable to retrieve metadata for ''. Ambiguous match found

Right now I am working with Visual Studio 2013,  ASP.NET MVC 5.0 and Entity Framework 6.1.1. One of the things I like about Visual Studio is the ability to generate scaffolded items. e.g. if I want to manage student records I just need to create a c# class named Student and Visual Studio can generate all the CRUD views and controller actions for me. This will save a lot of time and trouble for me.

However things might not always work as expected. I used this code generation feature quite a few times and it worked like a charm. But today it just didn't work. I got the below error.
There was an error running the selected code generator:
‘Unable to retrieve metadata for ‘HomeHome Models. ServiceproviderReview’. Ambiguous match found’

I did some research and tried the below things.
 1. Examine all the fields and properties to make sure that they don't have the same names with different casing
 2. Comment out most properties and keep only two properties (int:Id and string:Name)
 3. Rename the model, re-compile, regenerate the database
 4. Uninstall entity framework 6.1.1 and install 6.0.0
 5. Close visual studio and start again
 6. Clean the solution and rebuild
 7. Create another simple model class to just see what's going on

Unfortunately all of them did not work! In the end I was so frustrated after a couple of hours of trying all kind of things. I was almost going to restart my dev machine.  Then I decided to do one last attempt by creating a new DbContext. To my surprise it worked! I think that there must be some bug with Visual Studio / Entity Framework. After that I removed the new DbContext & the new connection string in web.config and switched to use the old DbContext. I was happy to see it still worked.

Comments

  • Anonymous
    September 08, 2014
    Hi. I have the same problema, but I am new in mvc and I was not able to fix it. Could you describe your source code?

  • Anonymous
    September 08, 2014
    You don't need to write code. Just choose to create a new DbContext in the dialog and then update it to connect to the same DB. Good luck

  • Anonymous
    April 03, 2016
    In my case, I revised my entities and found one property was overriding a base class property with keyword new and was causing ambiguitypublic class baseclass{ public int Id {get;set;}}public class myclass: baseclass{ public new string Id {get;set;}}Hope this helps

  • Anonymous
    May 19, 2016
    Thank you Paul!! I was also struggling with this problem for quite some time!