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
|
Hi, I have an entity that maps directly to a database table however I am populating it using a stored procedure because I wanted to pass in a parameter to the stored proc that would filter the results returned. This is all working fine but what I would now like to do is add a field to the entity that does not directly map to the table, it is a field from another table that I am joining on as part of the filter in the stored proc and it would be useful to have that field available in the application. I first added the field as part of the return form the stored proc. I then added it as an entity property to the entity in the light speed model. I run up the application and it all works fine, the new entity property is being populated with the value returned from the stored proc. But I run into problems when I try to edit one of the entities. i change a field (one of the ones that does map directly to a column in the database table) and save but i get an error. When i look in sql profiler i see that the save is attempting to include the new entity property as part of the update sql and of course it fails because that property is not actually a column in the table I am saving to. So then i went back to my entity in the light speed model and made the new propery "LoadOnly = true", I thought this would mean light speed wouldn't attempt to persist it to the database? But when i try agian to save it still attempts to update the property. Can you tell me if I am using the LoadOnly property incorrectly or do I need to set some other properties in addition to LoadOnly to get it working? If my post is a bit confusing i can post a small sample project to show more clearly what i mean thank you very much |
|
|
Using LoadOnly is correct for what you are trying to achieve - have you applied this through the designer or have you manually applied the attribute yourself? If its the latter make sure you apply it to the backing field rather than the property. LightSpeed only concerns itself with fields when inspecting a model so anything declared on your properties will be ignored. One thing you will probably also want to set on that field is a named aggregate so you can specify when you want to conditionally load in that extra bit of information.
Jeremy |
|
|
Hi Jeremy, thank you for your response. I have applied the change through the designer not manually - does that mean it should be working? I still am getting the same error when trying to save. Should I try setting the property manually instead of through the designer? I'm not sure I follow what you mean with setting a named aggregate. Are you saying that in order to get the LoadOnly option to work I need to set a named agggregate for that field? Or is the named aggregate just something i use if i only sometimes want to load the extra information e.g. if sometimes i want to load it from the stored proc that returns the extra information but other times I want to load it straight from the table where the extra information isn't available. thanks, kelly |
|
|
It should be working, check to see that the backing field that has been generated is marked as readonly. We have had a previous issue where if you name the field the same as one of our special fields (CreatedOn, UpdatedOn, DeletedOn, LockVersion, CreatedBy, UpdatedBy or DeletedBy) that the load only check will be bypassed since we are expecting to update these. If neither of those apply could you send us through a minimal repro (should be enough to just include that entity from your model) and we can have a look at what is going on with this.
Thanks! Jeremy
|
|
|
I checked the field and there is no set generated (only a get) so it is read only but is that what you meant by being marked as readonly? I cannot use the modifier readonly for the property as it won't compile but I thought maybe there is an attribute that should be set? but i'm not sure what it is. If you could provide a small code sample of what the backing field should look like that would be great. thanks |
|
|
actually, you can ignore the above quesiton. I figured it out. I'd been looking at the code behind the model only in the property but it turns out that in order for LoadOnly option to work you have to set the private variable referred to by the property to readonly. once I changed that it worked. But i'm unclear as to why the designer didn't do it automatically because the field was called CustomerId which is not one of the special fields (CreatedOn, UpdatedOn etc) that you listed. Although it is the name of a field in another entity i nthe same model - could that have caused it? anyway, doesn't really matter its all working now. thanks for your help on this matter |
|