{"action":"created","issue":{"url":"https://api.github.com/repos/MarimerLLC/cslaforum/issues/53","labels_url":"https://api.github.com/repos/MarimerLLC/cslaforum/issues/53/labels{/name}","comments_url":"https://api.github.com/repos/MarimerLLC/cslaforum/issues/53/comments","events_url":"https://api.github.com/repos/MarimerLLC/cslaforum/issues/53/events","html_url":"https://github.com/MarimerLLC/cslaforum/issues/53","id":105991598,"number":53,"title":"Child Object References","user":{"login":"Charles89","id":14233465,"avatar_url":"https://avatars.githubusercontent.com/u/14233465?v=3","gravatar_id":"","url":"https://api.github.com/users/Charles89","html_url":"https://github.com/Charles89","followers_url":"https://api.github.com/users/Charles89/followers","following_url":"https://api.github.com/users/Charles89/following{/other_user}","gists_url":"https://api.github.com/users/Charles89/gists{/gist_id}","starred_url":"https://api.github.com/users/Charles89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Charles89/subscriptions","organizations_url":"https://api.github.com/users/Charles89/orgs","repos_url":"https://api.github.com/users/Charles89/repos","events_url":"https://api.github.com/users/Charles89/events{/privacy}","received_events_url":"https://api.github.com/users/Charles89/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-11T11:24:17Z","updated_at":"2015-09-15T12:10:42Z","closed_at":null,"body":"For my application I try to implement child object references. I've read the \"Using CSLA 4: Creating Business Objects\" but feel like I'm missing or misread something. Here's the logical model I'm trying to implement:\r\n\r\n* class Building\r\n  * property AttributeList\r\n  * property RoomList\r\n\r\n* class Attribute\r\n  * property Description\r\n\r\n* class Room\r\n  * property AttributeValueList\r\n\r\n* class AttributeValue\r\n  * property Value\r\n  * references Attribute <-- puzzling\r\n\r\nSo basically each building has its own list of attributes and a list of rooms. Each attribute can then be given a value for any room.\r\n\r\nIn the UI, when editing a building, the AttributeList and RoomList can both be edited. The properties are lazy loaded because of performance reasons (think of a skyscraper with lots of rooms). The thing that puzzles me is how to implement the last property above. From the docs I should do it like this:\r\n\r\npublic class AttributeValue : BusinessBase<AttributeValue>\r\n{\r\n // snip\r\npublic static readonly PropertyInfo<Attribute> AttributeProperty = RegisterProperty<Attribute>(c => c.Attribute, RelationshipTypes.Child);\r\n // snip\r\n}\r\n\r\nSo how would I set the Attribute-reference from within the AttributeValueDal (objectfactory) without retrieving the list for every room? Should I go (Parent.Parent as Building).AttributeList.FirstOrDefault(x => x.Id == datarow.Id)? And how would the code be affected if the datalayer runs on a different machine?\r\n\r\nWe're using Csla version 4.5.501. Any pointers would be appreciated."},"comment":{"url":"https://api.github.com/repos/MarimerLLC/cslaforum/issues/comments/140369393","html_url":"https://github.com/MarimerLLC/cslaforum/issues/53#issuecomment-140369393","issue_url":"https://api.github.com/repos/MarimerLLC/cslaforum/issues/53","id":140369393,"user":{"login":"ajj3085","id":1903891,"avatar_url":"https://avatars.githubusercontent.com/u/1903891?v=3","gravatar_id":"","url":"https://api.github.com/users/ajj3085","html_url":"https://github.com/ajj3085","followers_url":"https://api.github.com/users/ajj3085/followers","following_url":"https://api.github.com/users/ajj3085/following{/other_user}","gists_url":"https://api.github.com/users/ajj3085/gists{/gist_id}","starred_url":"https://api.github.com/users/ajj3085/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajj3085/subscriptions","organizations_url":"https://api.github.com/users/ajj3085/orgs","repos_url":"https://api.github.com/users/ajj3085/repos","events_url":"https://api.github.com/users/ajj3085/events{/privacy}","received_events_url":"https://api.github.com/users/ajj3085/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T12:10:42Z","updated_at":"2015-09-15T12:10:42Z","body":"Usually when I have cases like that I handle it by assigning null for the attribute id (nullable int), and on the data portal side lookup all of the existing attributes (by description) and any that doesn't exist create them.  You could just create the Attribute instance on the dataportal side and ask it to save but that might result in duplicate Attribute descriptions, if that would be an issue.  \r\n\r\nIf you want to go with your design you could make Attribute a switchable class (it implements both root and child behaviors).  For existing attributes since it should be Old can I assume the description can't be changed once created (in this use case anyway) that would work, and for those that don't exist can be saved by having the AttributeValue do a FieldManager.UpdateChildren, which will trigger the child insert / update on Attribute if there's an instance.\r\n\r\nThis is a tricky use case, and I don't know there's any real clean way to handle it.  "}}