开发者

Entity Framework 4: The Phantom MDF

Yesterday, I decided to convert my application from LINQ-to-SQL to EF4 to take advantage of the code-first feature. I created my POCOs, a DbContext class, implemented new repositories classes and all was fine.

At some later point, I noticed that there was a typo in the filename EF used to create the SqlExpress MDF file. I moved the old DB out of its folder, cleared connection strings out of my config files, and let EF create a new, empty DB. It created the file, added a connection string to my app.config file, and the application works fine. However, when I look in the folder specified in the connection string, there is no MDF present. In fact, the folder doesn't even exist. Here is the connection string that EF added:

<add name="PhotoAlbum.Infrastructure.Properties.Settings.PhotoAlbumConnectionString"
            connect开发者_如何学编程ionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;C:\Src\Visual Studio 2010\Projects\PhotoAlbum\trunk\PhotoAlbum.Web\App_Data\PhotoAlbum.mdf&quot;;Integrated Security=True;User Instance=True"
            providerName="System.Data.SqlClient" />

Seeing that EF decided to put the file on C: instead of D: (where the folder does exist, but the file doesn't), I changed the connection string to:

<add name="PhotoAlbum.Infrastructure.Properties.Settings.PhotoAlbumConnectionStringg"
            connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;D:\Src\Visual Studio 2010\Projects\PhotoAlbum\trunk\PhotoAlbum.Web\App_Data\PhotoAlbum.mdf&quot;;Integrated Security=True;User Instance=True"
            providerName="System.Data.SqlClient" />

EF did not create a new file, or try to open an existing file, on the D: drive. This apparently makes no difference to EF, because it still is able to access this phantom MDF file.

I've searched my entire computer and there is no PhotoAlbum.mdf file anywhere on my system. Where has this file gone? Why can EF find it, but I can't?


This seems to only have been an issue with the CTP version of EF. The SQL CE files are showing up now.


What did you use to find the file? Is your operating system 64 bit? If it is, then if you are using a 32 bit tool to look into the filesystem, it will show you a virtual view of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜