0

I've imported an existing C# project in Visual Studio 2012, connected to a SQL Server 2012 database.

There are many compilation errors related to missing methods ("Add", "Remove" and "Find") on tables.

For example:

CITY city = db.CITY.Find (cityCode);

db.CITY is an ObjectSet< CITY >, a mapping of the existing table with the same name. But the method Find cannot be found. All the mapped tables are contained in the Model.Designer.cs (contained in Model.edmx, loaded from an existing database).

Any idea about these missing methods ? Old version code ? Missing configuration ?

I'm not a regular C#/Visual Studio developer. Maybe it's a basic problem.

I see a similar problem in "MusicStore 'System.Data.Objects.ObjectSet<....>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument"

The solution is: "The reason that worked is because you declared the Context using Object content and no DBContext. DBContext is wrapper on ObjectContext. Much easier to use. Somehow your exercise has mixed the 2 up. When creating the Model and Content in the place, if teh right project type is used and the Lastest nuget packages are in, you should get a T4 (template that generates code) that uses DBContext. The code you above is for accessing a context derived from DBContext. Suggest you take a close look at Your Context def and Regenerate it. Highly recommend that your move to DBcontext"

But I don't know how to do with Visual Studio.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Rififi
  • 121
  • 1
  • 11
  • 1
    Make sure that all the project references are valid as you might be missing some assembly containing extension methods. To do that, in Solution Explorer go in each of your project, expand References node and make sure that there are no yellow exclamation marks. – Kaspars Ozols Apr 30 '15 at 12:18
  • Thanks for your reply. All references are ok. There is no special mark. – Rififi Apr 30 '15 at 12:37

0 Answers0