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
|
This question is just being curious about noticing a behaviour with lightspeed. A different technique is used to implement the required functionality.
Using the following. 1. SQL Server 2008 2. Lightspeed 3.11 3. .Net 3.5 / C# Let say there are two tables in the database, Transactions and TransactionStatus. TransactionStatusId is a foreign key in Transaction table. The relationship is not marked for Eager Loading Transaction(Id, TransactionStatusId) TransactionStatus(Id, Description)
In the code, we have one Transaction object (transaction) . Lets say we make a database call to get the TransactionStatus object var status = (from ts in uow.TransactionStatuses where ts.Id == transaction.TransactionStatusId select ts).SingleOrDefault() If we then do the following transaction.TransactionStatus = status another database call is made to get ALL transactions with that status Curious why would that happen
|
|
|
This is to do with the reverse association, TransactionStatus.Transactions. I believe the idea is that we want to make sure that if you were to access status.Transactions after setting transaction.Status = status, you'd see that transaction was now part of that collection as expected. So we need to add transaction to that collection. But we can't do that until the collection is loaded. (In an earlier version of LightSpeed, we had a bug where transaction wouldn't appear in the status.Transactions collection unless the collection was already loaded when you did the set.) If my diagnosis is correct, then this is a possible source of redundant queries and we'll see if we can improve it. |
|
|
Thanks for the explanation. From the user perspective of this tool, it might be a better option to explicitly get a collection of transactions for a status when needed, then have it loaded automatically. The behaviour is not obvious by looking at code. There might not be a use for that collection in all the scenarios yet there is always a performance penality for getting the data. Having said that, other (better) techniques can be used for achieving the same thing. A change to Lightspeed may not be warranted but maybe make it more obvious in the Lightspeed documentation.
Cheers |
|