Reputation: 181
I'm trying to update a project to work in ASP.NET MVC4 using EF5(Database First approach as there is an existing db). I'm doing this with VS2010.
I am following the steps in this example.
These are the steps that I'm taking:
So after all that, it has created the classes to be used by EF; the problem is that these classes are all created with the project's root namespace, rather than the namespace I have provided it.
If I open up any of the generated classes, I get a list of errors that are fixed by manually changing the namespace to ProjectModel
I'd appreciate any thoughts.
Update:
This is a screenshot showing the project structure, an example of the generated code, and the compiler errors.
What's odd is that it only seems to throw an error for a namespace based on the structure, so in the image Project.Models as the namespace creates an issue, but if I type in anything else such as ProjectModels or Test the errors disappear. I can change the the namespace on all the files, sure, but every time the model changes and is updated, the namespace will be reset and the errors return.
This question seems to be the same issue as the one I am having, but unfortuntely, the only answer given advised checking references; I believe mine are fine as System.Data.Entity and EntityFramework are present.
Update 2: If I don't select all tables to during the code generation no namespace issues appear. I'm currently updating the model in 20 table intervals, with 400 tables though, I'd rather figure out what the actual issue is. I'm assuming it is due to the structure or name of one or more tables, but I'm not sure on whether or not there are any specific rules with regard table structure or naming with regard to EF.
Upvotes: 0
Views: 647
Reputation: 138
I achieved to set a custom namespace for the generated classes by setting the Custom Tool Namespace
field in the .edmx model properties, and also in the properties of both the .tt
files under it, using the Properties window.
Upvotes: 0
Reputation: 6294
If you are adverse to making changes to your data schema, you can configure Entity Framework to map the table name to a different type/class. Something like this may help.
Upvotes: 0
Reputation: 181
It appears as though one of the tables which is called System was conflicting with the .NET System namespace. I guess I'll just have to change the table name to something else.
Upvotes: 0
Reputation: 32058
Looks like your project is targeting .NET 2.0. Right-click on your project and choose Properties. make sure Target framework is set to .NET 4 or later.
Upvotes: 1