Questions tagged [savechanges]

DbContext.SaveChanges method in an Entity Framework method that saves all changes made in a context to the underlying database.

DbContext.SaveChanges method is Entity Framework method that saves all changes made in a context to the underlying database. More info: https://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext.savechanges%28v=vs.113%29.aspx

421 questions
92
votes
6 answers

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…
John B
  • 20,062
  • 35
  • 120
  • 170
65
votes
6 answers

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

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…
sa125
  • 28,121
  • 38
  • 111
  • 153
30
votes
2 answers

Is it possible to query Entity Framework before calling DbContext.SaveChanges?

In this simple example, I have two entities: Event and Address. I have a console application running every night to import event data from an XML source and add it to my database. As I loop through the XML event nodes (inside of the Entity Framework…
25
votes
3 answers

Using TransactionScope with Entity Framework 6

What I can't understand is if its possible to make changes to the context and get the changes in the same transaction before its commited. This is what I´m looking for: using (var scope = new TransactionScope(TransactionScopeOption.Required)) { …
Marcus Höglund
  • 16,172
  • 11
  • 47
  • 69
21
votes
2 answers

Entity framework query on just added but not saved values

I'm using Entity Framework from a couple of years and I have a little problem now. I add an entity to my table, with Entities.dbContext.MyTable.Add(obj1); and here ok. Then, I'd like to make a query on MyTable,…
Piero Alberto
  • 3,823
  • 6
  • 56
  • 108
14
votes
9 answers

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…
Zack Peterson
  • 56,055
  • 78
  • 209
  • 280
13
votes
2 answers

Entity Framework new transaction is not allowed because there are other threads running in the session, multi thread save

I'm tryng to save on a DB the log of a multi thread processo but I'm getting the following error: new transaction is not allowed because there are other threads running in the session. in each tread I have this function: internal bool…
andrea
  • 1,326
  • 7
  • 31
  • 60
12
votes
2 answers

How to get id from entity for Auditlog in Entity Framework 6

I know it's several similar posts out there, but I cannot find any with a solution to this issue. I want to add a (sort of) AudioLog when adding, changing or deleting entities (soft-delete) in Entity Framework 6. I've overridden the SaveChanges and…
11
votes
4 answers

Check if an insert or update was successful in Entity Framework

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,…
dev
  • 1,291
  • 3
  • 18
  • 26
10
votes
2 answers

EntityFramework show entities before saving changes

Entity Framework ObjectSet with its method ToList shows just saved entities. That means, when I call context.AddToCustomers(myNewCust); and then (without calling SaveChanges) myDataGrid.DataContext = context.Customers.ToList(); the DataGrid…
Mix Net
  • 103
  • 1
  • 4
10
votes
2 answers

Overriding SaveChanges in Entity Framework 5 Code First to replicate the behavior of an old legacy library

Our company ships a suite of various applications that manipulate data in a database. Each application has its specific business logic, but all applications share a common subset of business rules. The common stuff is incapsulated in a bunch of…
10
votes
0 answers

Entity Framework SaveChanges "hangs" the program

My code is pretty simple: Context.AddObject("EntitiesSetName", newObjectName); Context.SaveChanges(); It worked fine, but just one time – the first one. That time, I interrupted my program by Shift+F5 after the SaveChanges() was traced. It was a…
user1622345
  • 111
  • 1
  • 5
9
votes
2 answers

Assigning ids to entities with EntityFramework 4

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…
John Kaster
  • 2,509
  • 1
  • 33
  • 40
9
votes
2 answers

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,…
ChrisHDog
  • 4,473
  • 8
  • 51
  • 77
9
votes
2 answers

Saving in entity framework

I have read this article and still misunderstanding key moments. Don't we need call _context.SaveChanges() in every Delete/Update/... operations? If I change property of any entity does SaveChanges() submitted result to database or I must manually…
NET
  • 289
  • 3
  • 6
  • 13
1
2 3
28 29