Where is that file on my system?

僤鯓⒐⒋嵵緔 提交于 2020-01-11 12:05:27

问题


Am trying to learn ASP.NET MVC and search the internet in and out including SO. A lot of questions and answers about |DataDirectory| as where and how.

When debugging the site breaks:

"The model backing the 'ASPNETDBContext' context has changed since the database was created...".

Then I checked the path: |DataDirectory|ASPNETDBContext.sdf

 string path = AppDomain.CurrentDomain.GetData( "DataDirectory" ).ToString();

It points to the App_Data of the project but no file there.

The DB is entirely empty so deleting the thing is all I need.

My actual question I need to be answered: How to fix this properly?

made a follow-up: And additionally: Where is that file!


回答1:


The answer to your problem lies in reading Scott Guthrie's blog

For those who are seeing this exception:

"The model backing the 'Production' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance."

Here is what is going on and what to do about it:

When a model is first created, we run a DatabaseInitializer to do things like create the database if it's not there or add seed data. The default DatabaseInitializer tries to compare the database schema needed to use the model with a hash of the schema stored in an EdmMetadata table that is created with a database (when Code First is the one creating the database). Existing databases won’t have the EdmMetadata table and so won’t have the hash…and the implementation today will throw if that table is missing. We'll work on changing this behavior before we ship the fial version since it is the default. Until then, existing databases do not generally need any database initializer so it can be turned off for your context type by calling:

Database.SetInitializer<Production>(null);

Hope this will help you resolve the issue.



来源:https://stackoverflow.com/questions/12169590/where-is-that-file-on-my-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!