System.ArgumentException: The modelEntityContainer

2019-06-20 01:57发布

I've tried to use Entity Frameworks Power Tools Reverse Engineer Code First for a SQLServer database and received the following error:

System.ArgumentException: The modelEntityContainerName parameter 'testContext' contains characters that are not valid.
    at System.Data.Entity.Design.EntityModelSchemaGenerator..ctor(EntityContainer storeEntityContainer, String namespaceName, String modelEntityContainerName)
    at Microsoft.DbContextPackage.Handlers.ReverseEngineerCodeFirstHandler.ReverseEngineerCodeFirst(Project project)

Is there something I can do to continue or avoid this error or work around it.

Thanks.

2条回答
女痞
2楼-- · 2019-06-20 02:07

I am currently working with VS 2013 and Entity framework version 6.1.2 and ran into the same error.

I found this post by ErikEJ on Entity frameworks codeplex site: http://entityframework.codeplex.com/workitem/898#CommentContainer9

"@Greg - This issue is not fixed in Power Tools, but is fixed in the version 6.1 Tooling (Code First from Database) (just tested with SQL Compact)"

So, currently PowerTools cannot be used for this. However Entity framework 6 itself supports this. Just follow the workflow described here in this video: http://msdn.microsoft.com/en-us/data/jj200620

You add the entity data model item to the project and then choose "Code first from database".

Please note that the generated classes are a little bit different from what Power Tools would have created. Power Tools only uses Fluent API when configuring the database. The EF wizard on the other hand uses Data annotations by default and uses Fluent API only when necessary. However it is also possible to change the template files so that only Fluent API is used.

查看更多
贼婆χ
3楼-- · 2019-06-20 02:28

I had the same problem. My database was named sots-version-005, and the code was not escaping the name. The answer is to rename the database, and hopefully you are in a development environment where that is easy to do.

I used SQL Management Studio, right-clicked on the database, and renamed it 'sots5', eliminating all characters except alphanumerics.

查看更多
登录 后发表回答