views:

35

answers:

3

Hi.

I created a database and dbml in visual studio 2010 using its wizards. Everything was working fine until i checked the tables data (also in visual studio server explorer) and none of my updates were there.

using (var context = new CenasDataContext())
{
    context.Log = Console.Out;
    context.Cenas.InsertOnSubmit(new Cena() { id = 1});
    context.SubmitChanges();
}

This is the code i am using to update my database. At this point my database has one table with one field (PK) named ID.

*INSERT INTO [dbo].Cenas VALUES (@p0) -- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [1] -- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1*

This is LOG from the execution (printed the context log into the console).

The problem i'm having is that these updates are not persistent in the database. I mean that when i query my database (visual studio server explorer -> new query) i see the table is empty, every time.

I am using a SQL Server database file (.mdf).

EDIT (1): Immediate Window result

context.GetChangeSet()
{Inserts: 1, Deletes: 0, Updates: 0}
    Deletes: Count = 0
    Inserts: Count = 1
    Updates: Count = 0
context.GetChangeSet().Inserts
Count = 1
    [0]: {DBTest.Cena}
A: 

Can you provide the definition of ID in your database? Is it an identity?

Chuck Haines
No, it's just an integer.
codegarten
A: 

Hey,

Put a breakpoint on context.SubmitChanges(); and in your immediate window in VS, do:

context.GetChangeSet();

There is an inserts property and it should have one record. That will help tell if its queuing up an insert.

HTH.

Brian
The results is in the OP.
codegarten
Thanks, I posted before the edit.
Brian
A: 

If you construct a DataContext without arguments, it will retrieve its connection string from your App.Config or Web.Config file. Open the one that applies, and verify that it points to the same database.

Andomar
Yes, it is pointing to the right place ;)
codegarten
I guess you were right. The problem was that the wizard to created LinqToSql file (dbml) with the DataContext reading the Settings.settings file and not the App.config. So i was sure it was accessing the right database but it wasn't. I don't even know what it was doing <<Note to self: don't trust the wizards.
codegarten