savechanges

What is the best way to use the .SaveChanges() method in ADO.Net Data Services?

Does anyone have some good information on the usage of the .SaveChanges() method? I am experiencing a variety of issues when attempting to use the .SaveChanges() method on my data context object. I am taking data from an existing data source, creating the appropriate EntityFramework/DataService objects, populating those created objects...

Unable to save Entity Framework Inherited types.

I have implemented some table-per-type inheritance in my data model (basically have a "BaseEntity" type with all the base information for my items and a "Employer" type that inherits from the "BaseEntity" item). Everything appears to be set up correctly and when using the Entities (either via ADO.net Data Services or via Linq to Entitie...

Adding and Updating with LINQ to Entities

We are using L2E and REST in our project, and while I have been able to retrieve data from the db without issue, I am still not able to update or add new records to the db. I imagine that it's a syntax problem (we're still new to to linq), but I haven't been able to figure it out. We initially load the data in the dataservicecontext, a...

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

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 n...

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

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...

How to rollback a transaction in Entity Framework.

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 ...

How to have a form data-bound to an object with losing its values on postback

Hi I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity variable in the code file. The hierarchy of the item is Person.Orders I want the user to add/remove orders to this Person entity (Person.Orders.Add(order)), The problem is that while the entity is not saved yet, once the user makes a post back, the variabl...

Handling System Shutdown in WPF

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 ov...

Asynchronous ObjectContext.SaveChanges() ?

Hi all! I want the SaveChanges of the ObjectContext (Win apps) to SaveChanges asynchronously, will show a marquee (or controllable?) progress bar (this I can easily implement) for the user while he is able to continue working. I basically want to override the SaveChanges of the ObjectContext. Has anyone thought about this before? ...

c# Adding a new object to an object context returns "error occurred while updating the entries", duplicate entry for primary key

I'm having a problem trying to add an object to an object context in Entity Framework. Here is the code : //related object ids are retrieved from another context. //since I thought the problem could be linked to object loaded in this context, I tried to //close it and start on a fresh object context... int idetab = currentEtab.Id; lon...

Entity Framework won't SaveChanges on new entity with two-level relationship

I'm building an ASP.NET MVC site using the ADO.NET Entity Framework. I have an entity model that includes these entities, associated by foreign keys: Report(ID, Date, Heading, Report_Type_ID, etc.) SubReport(ID, ReportText, etc.) - one-to-one relationship with Report. ReportSource(ID, Name, Description) - one-to-many relationship wit...

Linq SaveChanges question

Should I bother doing this check to see if the object(s) saved correctly? if (objectContext.SaveChanges() > 0) It should just throw an exception if it didn't, right? ...

Check if insert(s)s or update(s) was successful in Entity Framework

Hello, 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 ...

Entity Framework - New entities with new children cannot be added with savechanges

I am creating an object called "letter" which has multiple "recipients" added to it. when savechages is called on the context i get this error. "Entities in 'EchoEntities.LetterRecipients' participate in the 'FK_LetterRecipient_Letter' relationship. 0 related 'Letter' were found. 1 'Letter' is expected." Also when only adding 1 recipie...

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

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 fir...

android onSaveInstanceState usage

Please guide in the following class what i should save in please remember i am using only one string which is i am retriving from getextra method and there is nothing which i think i should store in the following overridden method. protected void onSaveInstanceState(Bundle outState) { // TODO Auto-generated method stub super.on...

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

Hey! 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() funct...

Why would Entity Framework be able to retrieve entities but not save/update/delete them?

I have a WPF app with a local .MDF file on which I created an Entity Framework class model. Retrieving entities from the database works fine: //get entities using (var context = new TestDataEntities1()) { var customers = from c in context.Customers select c; foreach (var customer in customers) { ...

.Net Entity Framework SaveChanges is adding without add method

I'm new to the entity framework and I'm really confused about how savechanges works. There's probably a lot of code in my example which could be improved, but here's the problem I'm having. The user enters a bunch of picks. I make sure the user hasn't already entered those picks. Then I add the picks to the database. var db = ...

What is a good IDE for PHP? It has to auto upload to server on file-save

Can someone please recommend me a good editor for PHP that auto uploads on save? Basically, I do not want to store any files locally .. thx. ...