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
|
Hello, I am trying to create a test application and want to organize contacts. A contact can have several addresses (homeaddress, officeaddress, otheraddress). Therefor i wanted to use the valueobjects principle, because for me it sounds like the correct way. Ok, now i tried a lot of things, without any success. Although i do not find any example application for this. Do you have a simple step by step description? The Address is a ValueObject, but where/how does the "Contact" Entity know, that there are Home/Office/Other Addresses? Maybe i can't see the wood for the trees :) Thanks for any helping, Markus
A part of the code now is: public partial class Contact : Entity<long>
|
|
|
I don't think we have a sample for value objects at the moment, but there's additional info about them in the help file under Help Topics > LightSpeed > Creating Model Classes (scroll down to near the bottom) and Conventions (about half way down the page). Briefly: * On the CLR side, an entity may have several properties of the same value object type, e.g. public Address Home, public Address Office, etc. You can create these in the designer by dragging multiple arrows from the entity to the value object, and renaming them appropriately. * On the database side, each property of value object type maps to a set of columns, one per property of the value object. These are prefixed with the name of the entity property. E.g. if you have Home and Office properties of type Address, you would need columns called HomeStreet, HomeZip, OfficeStreet, OfficeZip, etc. Hope that clarifies things -- please ask further if it still doesn't make sense! |
|
|
Hi Ivan, thanks for your answer. Although it seems that i am lost ... Could you take a look at the attached screenshot of the designer - is that correct, what i did? If so, why can't i update the database? "... entity could not be synchronized with db". Another solution i can imagine, is (from my point of view it seems now the better way): Creating the column HomeAddressId and PrivateAddressId in the Contact Entity and then creating a ontoone association for each id to the Entity Address. But how? I can't find examples, sorry. Maybe you could give me the right keywords for searching or better the solution Anyway, thanks for helping. Markus |
|
|
Yes, what you've done is correct. The reason it can't update the database is that database synchronisation is not currently supported for value objects -- this not an error in your design, just a limitation of the designer (we have finite resources and haven't got round to it yet). I'm a bit surprised that the error message didn't explain why the entity was being excluded from synchronisation -- sorry about that, I thought we at least put up a message saying "because of the value objects." Anyway, if you decide to stick with the value object route and database sync is important to you then let us know and we will see if we can get it implemented for you. The other solution is, as you say, to have Address as an entity class rather than a value object class. This will mean addresses are held in their own table rather than within the Contact table. To do this, delete your Address value object and create an Address entity instead. Then, using the Toolbox, create one-to-one associations between the Contact and Address entities, and name them appropriately. You will not need to create HomeAddressId and PrivateAddressId properties explicitly -- LightSpeed will create these are part of the association. See Walkthroughs > Designer QuickStart for explicit steps (it talks about one-to-many associations but the same thing applies to one-to-one). |
|
|
Thanks. It works with the following way around: The "OfficeAddress" I created visually in the designer The "PrivateAddress" I have to create manually in a partial class, because a second one could not be created with the designer. I even checked out the nigthly build. Maybe a suggestion for improvement. public partial class Contact : Entity<long>
... but then it works. Thanks again for your time. |
|
|
Hmm, that's a bug -- the designer should allow you to create multiple one-to-one associations between the same entity types, but you're right, it's not doing so at the moment. Thanks for letting us know about this -- in the meantime, as you have found, the workaround is to declare additional associations in the partial classes. |
|
|
Any progress on this? Not being able to create multiple one-to-one associations is quite frustrating... :( |
|
|
Yes, sorry, this has been fixed but I failed to update this thread. Apologies! The fix is in current nightly builds which you can get from the Downloads tab (Express edition) or the store (retail editions). (Please uninstall 2.2 RTM before installing the nightly; otherwise you may see weird designer errors.) |
|