wpf - What could be causing db.SubmitChanges() to not work in linq-to-sql? -


I set a very simple example in WPF with LINQ-TO-SQL.

I can exit an object (page body) like this and I can change property and when I SubmitChanges < / Strong> (), then I do not see no errors but not saved .

  MandateContact DB = new major datatytext (); Var page itam = (PIID == 1 selection of P in DB.Pages items). SingleOther Default (); PageItem.Title = "changed"; Db.SubmitChanges ();  

Can not make changes due to change?

More information:

This does not work either, even db.ExecuteCommand also does not work, And oddly when F11 debugs do not take action in the changelog () or ExecuteCommand (), then why can not I move them?

 Use  (var db = new main datatytext ()) {var in pageItem = (p in db.PageItems where p.Id == 1 select p) .SingleOrDefault (); PageItem.Title = "changed"; Db.SubmitChanges (); Db.ExecuteCommand ("Insert in Page It's (values) values ​​('this is title')"); If (page itam! = Null) main content hair. Add (New Quick Form (Page Itam)); }  

More info:

db.log = console.You give me this:

  SELECT [t0]. [ID], [T.]. [Title], [T.] [Details], [T.]. [Display order] from [dbo] [PagesEm] AS [T.] Where [T] [ID] = @ P 'Test Page Manager 23434.vshost.exe' (Managed): Loaded 'C: \ Windows \ Assembly \ GAC_MSIL \ PresentationFramework.resources \ 3.0.0.0_de_31bf3856ad364e35 \ PresentationFramework.resources.dll' - @ P0: Input int (size = 0; prep = 0; scale = 0) [1] - Reference: SqlProvider (Sql2008) Model: Attitated Metmodel Build: 3.5.30729.1 Insert Page Ets (Title) values ​​('This is the title' ) - Reference: SqlProvider (Sql2008) Model: Attitated Metmodel Build: 3.5.30729.1 Thread has been removed from 0x1190 code 0 (0x0).  

Answer

The solution was three times:

  • I was seeing a different database than I was In Visual Studio, the solution:

    var db = new main datatytext (@ "c: \ user \ test user \ document \ visual studio 2008 \ projects \ testpage manager 23434 \ testpage manager 23434 \ data \ Main .mdf "))

  • That worked the update but SubmitChanges (not), the solution was to set the primary key .

  • It was still not showing all the things, problems I opened many "show data" windows which were not open

< / Div>

It is possible that you do not have a primary key defined in the table in SQL Server


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -