开发者

LinqToSQL not updating database

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 da开发者_运维问答tabase (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}


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜