savechanges

ObjectContext.SaveChanges() violates primary key, throws UpdateException?

徘徊边缘 提交于 2019-11-29 12:19:54
Paraphrasing from this MSDN documentation ... An INSERT statement is generated by the Entity Framework and executed on the data source when SaveChanges is called on the ObjectContext. If the INSERT operation succeeds, server-generated values are written back to the ObjectStateEntry. When AcceptChanges is called automatically at the end of the SaveChanges execution, a permanent EntityKey is computed by using the new server-generated values. This does not seem to be occurring in my code. When I call ObjectContext.SaveChanges() , an UpdateException is thrown with InnerException.Message value:

How can I cancel a user's WPF TreeView click?

最后都变了- 提交于 2019-11-28 19:41:55
I've got a WPF application with a Treeview control. When the user clicks a node on the tree, other TextBox, ComboBox, etc. controls on the page are populated with appropriate values. The user can then make changes to those values and save his or her changes by clicking a Save button. However, if the user selects a different Treeview node without saving his or her changes, I want to display a warning and an opportunity to cancel that selection. MessageBox: Continue and discard your unsaved changes? OK/Cancel http://img522.imageshack.us/img522/2897/discardsj3.gif XAML... <TreeView Name=

How to rollback a transaction in Entity Framework

我们两清 提交于 2019-11-27 23:06:28
string[] usersToAdd = new string[] { "asd", "asdert", "gasdff6" }; using (Entities context = new Entities()) { foreach (string user in usersToAdd) { context.AddToUsers(new User { Name = user }); } try { context.SaveChanges(); //Exception thrown: user 'gasdff6' already exist. } catch (Exception e) { //Roll back all changes including the two previous users. } Or maybe this is done automatically, meaning that if error occurs, committing changes are canceled for all the changes. is it? Shimmy OK I created a sample a application like the example from the the question and afterwords I checked in the

Find an element by id and replace its contents with php

隐身守侯 提交于 2019-11-27 07:05:47
问题 I want to use PHP to search through the contents of a file for an element with a specific id, replace its contents, then save my changes to the file. I'm able to load in the HTML, and save it back out again, but am having trouble with the 'find and replace' (currently trying to use preg_replace). Here's what I have so far: <?php // read in the content $file = file_get_contents('file.php'); // parse $file, looking for the id. $replace_with = "id='" . 'myID' . "'>" . $replacement_content . "<";

Fabric.js - how to save canvas on server with custom attributes

Deadly 提交于 2019-11-26 19:28:49
I'd like to be able to save the current canvas' state to a server-side database, probably as a JSON string, and then later restore it with loadFromJSON . Typically, this is easily accomplished using: var canvas = new fabric.Canvas(); function saveCanvas() { // convert canvas to a json string var json = JSON.stringify( canvas.toJSON() ); // save via xhr $.post('/save', { json : json }, function(resp){ // do whatever ... }, 'json'); } And then function loadCanvas(json) { // parse the data into the canvas canvas.loadFromJSON(json); // re-render the canvas canvas.renderAll(); // optional canvas

Fabric.js - how to save canvas on server with custom attributes

余生颓废 提交于 2019-11-26 17:26:28
问题 I'd like to be able to save the current canvas' state to a server-side database, probably as a JSON string, and then later restore it with loadFromJSON . Typically, this is easily accomplished using: var canvas = new fabric.Canvas(); function saveCanvas() { // convert canvas to a json string var json = JSON.stringify( canvas.toJSON() ); // save via xhr $.post('/save', { json : json }, function(resp){ // do whatever ... }, 'json'); } And then function loadCanvas(json) { // parse the data into

When should I call SaveChanges() when creating 1000&#39;s of Entity Framework objects? (like during an import)

穿精又带淫゛_ 提交于 2019-11-26 10:09:52
问题 I am running an import that will have 1000\'s of records on each run. Just looking for some confirmation on my assumptions: Which of these makes the most sense: Run SaveChanges() every AddToClassName() call. Run SaveChanges() every n number of AddToClassName() calls. Run SaveChanges() after all of the AddToClassName() calls. The first option is probably slow right? Since it will need to analyze the EF objects in memory, generate SQL, etc. I assume that the second option is the best of both