none
Entity framework 5 cannot save data to sql server compact 4.0 database RRS feed

  • Question

  • Hi all,

        I got some issues when I try to use entity framework to add data to the sql server compact 4.0 database.

       Here is what i do:

        1. Create a sql server compact 4.0 database and add a table named test with two columns: Id (int),  string(nvarchar).

         2. In vs 2012, add a entity framework model, selected generate from database, then here comes a auto generate Model3.edmx.

       3. using code below try to add data to database.

               


     using (testEntities te = new testEntities())
                {
    
    
                    hello h = new hello();
    
                    h.string_ = "hello";
    
                    te.hello.Add(h);
    
                    string hello = "hello";
    
                    te.SaveChanges();
    
                }

        BUT when i check the database, I cannot find the data, it means that the data did not really save to database.

    So what's wrong with my code?  can anyone can help me?

    Thanks a lot


    Simon Huang

    TechNet Community Support


    • Edited by Shimin Huang Wednesday, December 3, 2014 2:13 PM
    Wednesday, December 3, 2014 2:12 PM

Answers

  • Look in the bin/debug folder for a copy of your database file. Solutions include use full path in connection string, do not include the database file as content, set copy=never...

    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    • Marked as answer by Shimin Huang Wednesday, December 3, 2014 3:23 PM
    Wednesday, December 3, 2014 2:25 PM

All replies

  • Look in the bin/debug folder for a copy of your database file. Solutions include use full path in connection string, do not include the database file as content, set copy=never...

    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    • Marked as answer by Shimin Huang Wednesday, December 3, 2014 3:23 PM
    Wednesday, December 3, 2014 2:25 PM
  • Hi ErikEJ,

    Thanks a lot, just like you say, I copy the database to my project, then the change cannot be saved, when I direct connect to the database in the file system, it worked.

    Thanks


    Simon Huang

    TechNet Community Support

    Wednesday, December 3, 2014 3:23 PM