savechanges

Assigning ids to entities with EntityFramework 4

烂漫一生 提交于 2019-12-22 04:03:47
问题 I'd like to implement "default" Id generation support for my entities. When saving the entity, I'd like EntityFramework to only generate the id value for the Entity if it's not already set. If the ID already has a non-null, non-zero value, I want to have that entity ID preserved when the entity is saved in the database. I'm migrating data from a legacy data model (EntityFramework model created from the old database) to a newly created (model-first) EntityFramework model. Let's call the old

How to revert/recover .m file to a previous version? (autosaved blank by mistake and xcode crashed - no Source Control, no Time Machine)

霸气de小男生 提交于 2019-12-21 16:34:01
问题 I've tried to search for the answer but I cannot precisely define the terms without falling under wrong threads all the time. What happened: Accidentally I've selected all the code inside a file.m and deleted it all. It became a full blank document . When I pressed Ctrl+Z to UNDO it, the xcode crashed . The problem: When I reopened the xcode (after the crash) , the file was still all blank ( It was autosaved seconds before the crash as a blank document ) - losing all my code . I could not use

What is the best way to determine if Object has been changed?

南楼画角 提交于 2019-12-21 02:46:39
问题 I made some "save" bean functionality in my Java Web Application (JSF1.2, RichFaces). It is using JAXB to turn it into an XML string and then it is stored in the database. If the user loads this back, I want to notify the user if the (bean)content is changed and it should be saved again. My idea is to override the hashCode() function 'with' org.apache.commons.lang.builder.HashCodeBuilder , however I have lots of fields and child elements. Is there any other way to handle this kind of

How do I properly handle a PreviewMouseDown event with a MessageBox confirmation?

独自空忆成欢 提交于 2019-12-20 03:47:12
问题 Earlier I asked how to cancel a WPF TreeViewItem.Selected event. The answerers suggested I instead handle the PreviewMouseDown event before the selection even takes place. That makes sense. I've tried to do that... XAML... <TreeView Name="TreeViewThings" ... PreviewMouseDown="TreeViewThings_PreviewMouseDown" TreeViewItem.Expanded="TreeViewThings_Expanded" TreeViewItem.Selected="TreeViewThings_Selected" > Visual Basic... Sub TreeViewThings_PreviewMouseDown(...) If UnsavedChangesExist() Then e

Check if an insert or update was successful in Entity Framework

旧城冷巷雨未停 提交于 2019-12-19 18:38:01
问题 In ADO.NET, ExecuteNonQuery() "For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command" (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx) In EF v1, context.SaveChanges() method returns "The number of objects in an Added, Modified, or Deleted state when SaveChanges was called." (http://msdn.microsoft.com/en-us/library/bb739065.aspx) Please tell, when multiple entities (or single entity) are added or

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

非 Y 不嫁゛ 提交于 2019-12-18 07:09:31
问题 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

How to rollback a transaction in Entity Framework

社会主义新天地 提交于 2019-12-17 16:28:32
问题 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? 回答1: OK I

Handling System Shutdown in WPF

烂漫一生 提交于 2019-12-13 13:23:20
问题 How can I override WndProc in WPF? When my window close, I try to check if the file i'm using was modified, if so, I have to promt the user for "Do you want to save changes?" message, then close the file being used and the window.However, I cannot handle the case when user restarts/shutdown/logoff when my window is still open.I cannot override WndProc since I am developing using WPF.I have also tried using this sample MSDN code.This is what I did private void loadedForm(object sender,

Entity Framework - Initial Save is slow

蹲街弑〆低调 提交于 2019-12-12 10:12:59
问题 We are implementing a system using EF4 and WPF. We are noticing an issue with the initial saving of data: when the initial SaveChanges is run there is a 4 to 6 second delay when context.SaveChanges() command is run. Every subsequent SaveChanges is very fast with no noticable delay. This is not a major issue - but an annoyance none-the-less. Has anyone out there experienced this issue and know a way around it? Thanks 回答1: Problem solved: the answer was to pre-generate the model's views. The

Saving only difference in custom class matlab

会有一股神秘感。 提交于 2019-12-12 03:33:55
问题 I have defined a class Results that is supposed the hold the results of a certain operation. I perform this operation 10.000 times and add the result to the result class. Since this operation is slow, to prevent data loss, I save the temporary results every time (that is, I call save('tempResults.mat', 'obj') inside a method in my class) The issue is that I write from scratch the whole class every time. But by the 5000th time, the class is already ~ 1 Gb big. It is unusable to write 1 Gb of