我的系统上的文件在哪里? [英] Where is that file on my system?

查看:133
本文介绍了我的系统上的文件在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图学习ASP.NET MVC并搜索互联网,包括SO。关于| DataDirectory |的很多问题和答案



当调试站点断点时:



支持ASPNETDBContext上下文自数据库创建以来已更改...



然后我检查了路径: | DataDirectory | ASPNETDBContext.sdf

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

它指向项目的App_Data,但没有文件。



数据库是完全空的,所以删除的东西是我需要的。



我的实际问题我需要回答:如何正确地解决这个问题?



进行了跟进

$ 回答您的问题在于阅读 Scott Guthrie的博客


对于那些看到此异常的人:



自从创建数据库以来,支持生产上下文的模型已经更改。手动删除/更新数据库,或者使用IDatabaseInitializer实例调用Database.SetInitializer。



下面是发生了什么以及做什么:



当模型首次创建时,我们运行一个DatabaseInitializer例如创建数据库(如果不存在)或添加种子数据。默认的DatabaseInitializer尝试将使用模型所需的数据库模式与存储在使用数据库创建的EdmMetadata表(当Code First是创建数据库时)中的模式的哈希进行比较。现有的数据库不会有EdmMetadata表,所以不会有哈希...和今天的实现将抛出,如果该表丢失。我们将在发布fial版本之前改变这种行为,因为它是默认值。在此之前,现有数据库通常不需要任何数据库初始化程序,因此可以通过调用以下方式关闭您的上下文类型:




  Database.SetInitializer< Production>(null); 

希望这有助于您解决问题。


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!

解决方案

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.

这篇关于我的系统上的文件在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆