This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Does Lightspeed support deep save ? I havent found information about that, so I`m asking. |
|
|
I'm not sure what you mean by "deep save." When you do a SaveChanges, LightSpeed saves everything in the unit of work (i.e. runs all pending inserts, updates and deletes). Can you describe in more detail what behaviour you're looking for? |
|
|
[quote user="ivan"] I'm not sure what you mean by "deep save." When you do a SaveChanges, LightSpeed saves everything in the unit of work (i.e. runs all pending inserts, updates and deletes). Can you describe in more detail what behaviour you're looking for? [/quote] I want to save entity with its related children entities. for example: I have created NEW object graph (Customer with Orders, each Order with OrderItems), and I`m doing something like that:
uow.Add(customer); uow.SaveChages();
then new customer will be saved with his orders and orderItems
|
|
|
Yes, that happens automatically. When you add a Customer to the UOW, all its child Orders get added too, and each of their child OrderItems. So when you do a SaveChanges it saves the whole kit and caboodle. |
|
|
Woooow !!!
|
|
|
[quote user="ivan"] Yes, that happens automatically. When you add a Customer to the UOW, all its child Orders get added too, and each of their child OrderItems. So when you do a SaveChanges it saves the whole kit and caboodle. [/quote] I just tried that, and it didn't work. I'm using SQL Server with Identity Column IDs (the SQL Server default) and trying to add, say, the Customer and several Orders. What I get is an exception, "System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'OrderID', table Customers..." -- you get the idea. What might I be doing wrong here? Thanks, Dave |
|
|
That looks like there's something awry in the database schema / model. If a Customer has several Orders, shouldn't table Orders have a CustomerID column rather than table Customers having an OrderID column? It sounds like what you have is a single Customer.Order, rather than a Customer.Orders collection, and that Customer.Order is non-nullable but is not being set before the SaveChanges(). |
|
|
Ivan - That's what I get for sending off a help request just before heading out for the day. I misread the error message completely, and now I have egg on my face. The real problem was in not setting the identity property on the Orders table, so the error message really said "Cannot insert the value NULL into column 'OrderID', table 'Orders'..." I transcribed the names from my actual table and column names into the ones used in the post I was replying to, and didn't notice the obvious. I set the identity property for the ID column in the 'Orders' table, and all is well. Thanks, Dave |
|