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 need to create a replacement application for a client and I need to first make sure I understand how Lightspeed operates. In general the application performs an audit task of a users computer. The audit is performed locally on a regular basis and periodically by the admin on both the system and any system resources the user has allocated. From this we can assume that in general there is little or no cross talk between user tasks and admin tasks. My design would use Lightspeed to interface to VistaDb for the user task and a more robust multi user database such as Oracle or Sql Server for the admin tasks. Since the original database was pre windows the design is simple and there are no foreign keys embedded and all relational "keys" can be established in the application. So the basic use for the database is to store information. Lightspeed is of course a bit more sophisticated and could do a lot more and for this task that could be a problem. This leads to the following questions: 1 - When data is written to a table that has an auto index Lightspeed writes the record and then immediately reads back the Id assinged to it. While this is understandable can the read back be disabled? 2 - The interface to the database is done by the UnitOfWork. This seems ok but it seems that the basic design assumes that the database connection will remain active thoughout the functional process. If so how does one create a web based application or a remote connection that functions in a "disconnected" fashion? In this application it is unlikely that any user specific data will be overwritten by another user as the database is local and on the off chance that the admin task is running whle the user task is the worst possible problem would be that the most recent changes that result from the user task would not be seen by the admin task (the admin task reads the users local Database for user system data). 3 - Ideally I would like to read all the data required for the audit task from the database and place it into strongly tyoed ICollection's or IList's and then disconnect and perform the actual audit reconcile the data and allow the user to make any modifications allowed then establish the connection via a new UnitOfWork and Add the new or modified records to the UOW and SaveChanges. Is this possible or do we need the UOW to remain active? 4 - With respect to tranaction scope. When is a tranaction started and can we control or predict them? This seems to be an issue for VistaDb and in the latest version they offer the ability to ignore them totally as they can really slow things up. Thanks in advance for your help.
|
|
|
1. To clarify, you are talking here about the IdentityColumn identity method (with an appropriate auto increment or identity setting on the database PK column), right? In this case, no, the read back cannot be disabled. LightSpeed always wants to know the ID of the entities it manages (e.g. to wire up relational keys). What's your concern about the read back? 2. The usual practice for a Web based application is to create a unit of work per HTTP request. See http://www.mindscape.co.nz/blog/index.php/2008/05/12/using-the-unit-of-work-per-request-pattern-in-aspnet-mvc/ for discussion of this. That is, the application rehydrates (using IDs or whatever) entities from the database for each request. A "disconnected" application would likely use a similar pattern, though care is required when using entities (e.g. removing children) while disconnected. 3. The conditions under which you need the UOW to remain active are a bit complicated, but a good rule of thumb is: if you are going to be modifying an entity or its associations, the UOW needs to be active; if you are only reading from the entity, the UOW does not need to be active. So it depends on what the "data required for the audit task" is. Suppose the data is just a list of categories which need to be audited on this run. Then you can dispose the UOW that was used to load this list, and create all the audit records in a new UOW and save that. But if you were planning to modify the categories, then you would probably want to keep the original UOW active (you can get around this by Adding or Attaching entities loaded by the old UOW into a new UOW, but this starts to get more complicated). 4. SaveChanges creates a transaction if one is not already in progress and does all its work within that transaction. You can't control this, though you can predict it (and if desired pre-empt it by creating a TransactionScope or by calling BeginTransaction yourself). Transactions can also be created when LightSpeed needs to allocate IDs using a key table or sequence. We'd be somewhat reluctant to provide an option to run SaveChanges without a transaction, because a SaveChanges could be sent to the database in several batches, and we don't want to end up in a position where some entities have been saved and others have not. The only one of Jason's five scenarios in http://www.vistadb.net/blog/post/2009/04/24/Transactions-can-hurt-performance.aspx where we create a transaction that's not necessary is scenario 2, single isolated record insert/update. (Again ignoring the KeyTable case.) We could try to add some smarts to LightSpeed to detect if a SaveChanges is going to be be a single action, and avoid creating a transaction in this case, but that's potentially rather complicated so it's not likely to happen in the near future. I'm assuming your audit runs are going to generate a reasonable number of records to be inserted each time, so I would have thought you would be wanting a transaction anyway. Hope this helps -- happy to go into more detail if required. |
|