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
|
[Using Lightspeed 4] I’ve got a simple database relationship of company and staff. A company is related to the managers of the staff and the managers have child staff that they own. Both ultimately belong to a company.
I’m encountering a problem when trying to save a new company entity with managers and child staff all populated as it seems that I’m not correctly accessing the as yet unsaved company Id when trying to save the Child Staff record – see static partial void BeforeCopyStaff(StaffDto dto, Staff entity) in StaffDto (below)
Attached is a database script and a sample project with 2 nunit Tests in to highlight my issue – if you can let me know where I’m going wrong I’d really appreciate it . Thanks |
|
|
The problem is that your Staff DTOs don't have an easy way of referring to unsaved parents -- they depend on a parent ID reference and that's not meaningful for unsaved parents. The easiest way to fix this up is probably to just fix up the newly created Staff entities with the right company after the Company entity is created:
One thing to note is that your CompanyDto.Manager collection may be misnamed -- at the moment you copy all staff from the Company entity into the CompanyDto.Manager collection. You should rename the DTO collection to Staff, or copy only top-level managers into the collection. At the moment your test will still fail even with the above fix, because |
|
|
Ivan This worked perfectly thanks and I've updated the top level collection to only return managers and it works as expected. Cheers |
|