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
|
I have seen with your logging system that when I change just one property of an entity and I call SaveChanges of the UnitOfWork, this create a query that update all fields instead of commiting just the fields that have a change. Is there any way to tell LightSpeed, DataContext, UnitOfWork or any other object to track changes and just create a query with fields that have changes?
Example: I have an entity Person with a FirstName and a LastName. I load the entity with a UnitOfWork and change the FirstName. When I call SaveChanges of the UnitOfWork, I want a query like this: UPDATE Person SET FirstName='John' WHERE Id = 10
Thank you in advance |
|
|
Yes, you can do this by turning on Optimistic Concurrency Checking on the entity. In the designer, select the entity, go to the Properties window, and set Optimistic Concurrency Checking to True. Note that this adds a versioning field to the entity so that LightSpeed can fail the save if the database record has changed since the entity was loaded. This is important because otherwise a partial save could result in inconsistent data. The database must contain a corresponding column. So after turning on OCC in the designer, use Update Database to add the necessary LockVersion column to the database. |
|
|
I have tried what you said and it's work great except for External Ids. Every column in the table that changes is always commit and also all external Ids columns and finally the LockVersion column. It is normal that all external Ids columns is always commit? |
|
|
I'm not sure what you mean by "external IDs." Do you mean the XxxId fields associated with associations? For example, if an Employee has a Manager association, it will also have a ManagerId field -- is the ManagerId field an example of an "external ID"? (Sorry if this is a dumb question -- just not familiar with this terminology.) |
|
|
Sorry,
What I mean by External Ids is Foreign Key and is exactly what you said.
Example: If I have a table with these fields: FirstName: String LastName: String ManagerId: Int
If I change only the FirstName and try to SaveChanges, the auto-generated query also send the ManagerId value. |
|
|
This is a limitation of the change tracking implementation. Internally, setting the Employee.Manager property does not currently add the Employee.ManagerId property to the save list (this is to do with the way associations and foreign key fields are wired up within LightSpeed). Therefore, we have to be conservative and save all foreign keys, just in case they have changed. This is something we could probably improve, but it is a low priority because the reason people are interested in partial saves is usually to avoid saving big fields like BLOBs or TEXT fields. Foreign key fields, by contrast are usually very small, so the overhead of saving them unnecessarily is small too. |
|
|
Thank you very much for the fast reply. I'm totally satisfy with that because the main reason why I want to not commit all fields is exactly for what you said: to prevent sending blob and large text fields. The reason why I ask about foreign keys is because I thought that I was wrong in my approach to use the concurrency property of the entity. I now have a large table with 40 fields that send 8 fields values instead of 40. Viva Legacy application code! :) Thank you again. |
|