1

I'm learning about ADO.Net entity framework, and I'm stuck at adding entity table object to the database.

I have a local database in solution called testDB. It has two columns - id(primary, unique, identiy),name(varchar(100)) and entity for it. The main application code is here below. Problem is, that using this code it doesn't add anything to the table, but also I'm not having any errors. What could go wrong?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace entityproject
{
class Program
{
    static void Main(string[] args)
    {
        String someString;
        someString = "Just a test";

        testDBEntities tdbEntity = new testDBEntities();
        test tblTest = new test();

        tblTest.name = someString;
        tdbEntity.test.Add(tblTest);
        tdbEntity.SaveChanges();
    }
 }
}

App.config here http://pastie.org/6980938

4
  • Are you sure it's not getting added? The code looks ok to me. Double-check that the database in your connection string in the .exe.config is the same one you're looking at. Commented Mar 21, 2013 at 19:17
  • I noticed, that in App.config the <configuration> has the blue swirly line saying 'the configuration element is not declared' even though its there Commented Mar 21, 2013 at 19:21
  • Weird. Maybe post the whole app.config here (except password of course), and let's see if we can figure out if there's anything wrong with it. Commented Mar 21, 2013 at 19:22
  • pastie.org/6980938 there is no pass, since its just for the test Commented Mar 21, 2013 at 19:25

1 Answer 1

1

I think I know the problem - had the same thing last time I tried using SQL CE.

The connection string doesn't point to the sdf file that you created - it uses a new one that I believe gets put into your bin\Debug or bin\Release directory (in your config file as data source=|DataDirectory|\testDB.sdf), with your EXE and DLLs. If you check that directory, I bet you'll find another sdf file there, that has a bunch of records added.

If you want to use the sdf that you've already created, change the connection string to point specifically to that file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.