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 an entity that maps to a database table that I do lightspeed generated CRUD on. But I also want to return a set of these entities using a stored proc with the .FindBySql method. The proc does some complex querying to return an extra column with some aggregate data in it that I only ever need to read from - so its independent from the CRUD operations. I have that column defined in the designer - but because its not needed for update/insert I have set Transient=True. But when this is set to true the aggregate data isn't populated in the column when I load it using .FindBySql... What am I missing? Is there a way to load data from a stored proc for fields that are then ignored in normal Update/Insert operations? Thanks. |
|
|
Transient fields are entirely ignored by LightSpeed: they are neither loaded nor saved. To have a field that gets loaded from the database during a SELECT, but is not saved on an UPDATE/INSERT, set the (backing) field to readonly. (And do NOT apply [Transient].) See http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=2685&PostID=8517 for more info. |
|
|
Note that if you include this field then LightSpeed will also want to populate it during Find and FindById operations -- which will cause errors if the column doesn't exist in the table. We don't have a way to mark a field as an "optional" field that will be populated only during certain operations: the entity to column mapping is assumed to be static and independent of how you perform the query. |
|
|
Okay - sweet - got that working okay. Now problem is with the .FindBySQL method. Each time I run it I pass in a different stored proc parameter value that changes the aggregate data value returned into the readonly field. Problem is - despite the stored proc being run (and thus the round-trip to the db completed and results returned), Lightspeed only appears to be looking at the id value of each row and thinks "I've already loaded that entity - so I won't bother applying the returned values" and the new values I want are ignored... How do I tell the object tree (is that the name?) that I want the entity's refreshed from the returned data? Thanks! |
|
|
Currently, LightSpeed always returns entity instances from the unit of work (identity map) if possible. It is not possible to update an entity within a unit of work. This applies to all Find methods, not just FindBySql. Therefore, if you need to get new values regardless of whether the entity is already loaded, you must perform the query in a new, separate unit of work. |
|
|
Hmmm... So how would I solve my problem? Can I load a new entity in a new UOW and then attach or merge it to the current UOW? Or would I have to copy over property by property manually... Can I have some suggestions of a workaround please... |
|
|
Yes. Load the new entity into a new UOW. Then attach it to the current UOW using the Attach method. If there are associations to the old instance of the entity, I think you'll also have to update these to the new version -- LightSpeed does NOT automatically re-evaluate foreign keys where the association has already been loaded. You might also want to check out JD's blog post on rich client development. |
|