문제

I'm trying to use Entity Framework 4 for a small database application I'm writing to keep record of downloaded files. When running the application I set a break point after the tableName.Add() method, before the .SaveChanges() method and I can see the data saved into the entity; then I have another break point after calling the .SaveChanges() method, and look into the database to find there is no record saved to it. I have found a lot of similar questions, but I have not found the solution to my particular problem. Here is the code:

    public void StartNewDownload(string FileID)
    {
        DateTime startTime = DateTime.Now;

        FilesDBEntities db = new FilesDBEntities();
        int startedID = (from dr in db.tblDownloadResults
                         where dr.Value.Equals("Started")
                         select dr.ResultID).First();
        tblDownloads myDownload = new tblDownloads { FileID = FileID, StartDateTime = startTime, ResultID = startedID };
        db.tblDownloads.Add(myDownload);
        db.SaveChanges();
    }

Any help is appreciated.

Thanks!

도움이 되었습니까?

해결책

Pawel, you guided me in the right direction. The entity had the data, but the database I was looking into did not. But after reading your comment I ran the program from Visual Studio and used Process Monitor to monitor any operations to *.sdf files. This helped finding out that upon building the solution, it would create another database file to the bin\Debug folder. I forgot the database Build Action property was set as "Content".

Thanks!!

다른 팁

You can use SQL Server Profiler to see if the entity framework has really called the database.

(The tool is not included in SQL Server Express)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top