Hi Rocky
I'm using CSLA.NET 4.0.1 (didn't install 4.1.0 yet)
I have a Inbox class defined like this:
[Serializable]
public class Inbox : ReadOnlyBase<Inbox>
I have some properties (auto properties mostly but that's besides the point) and then some child properties declared as follows:
public static PropertyInfo<SentByUserDocList> SentByDocumentsProperty =
RegisterProperty<SentByUserDocList>(p => p.SentByDocuments,
"Sent By Documents", RelationshipTypes.Child);
public SentByUserDocList SentByDocuments
{
get { return GetProperty(SentByDocumentsProperty); }
}
You also need to know a bit about the child type:
[Serializable]
public partial class SentByUserDocList :
ReadOnlyListBase<SentByUserDocList, SentByUserDocInfo>
mostly because it's a ReadOnlyListBase and its items are
[Serializable]
public partial class SentByUserDocInfo :
ReadOnlyBase<SentByUserDocInfo>
so ReadOnlyBase too.
The problem is VS2010 is complaining about the
RelationshipTypes.Child
part saying
Argument type 'Csla.RelationshipTypes' is not assignable to parameter type 'SentByUserDocList'
I suppose this means ReadOnlyListBase objects can't be child. I also suppose that's why the class
SentByUserDocList
complains about
MarkAsChild();
PS - I started with non-ReadOnly objects and I was trying to transform everything into RO.
Regards
Child is editable object concept, not readonly object. You should be able to remove child related code, and everything will still work just fine.
The child relationship type value is only meaningful for editable objects, as it controls some read-write interactions.
You can absolutely have child objects in a read-only object graph, but those graphs are much simpler (almost by definition - no undo, no persistence, etc), so that relationship type has no meaning.
I suppose it could be argued that it should be allowed (and just ignored) to provide consistency.
The child relationship type value is only meaningful for editable objects, as it controls some read-write interactions.
Hi Rocky,
I was under the impression child/lazyload flags are needed to tell CSLA to use Child_ instead of DataPortal_ methods. The templates show ROChild and ROChildList but none of the examples show a child or a child list used as a property. I mean:
EditableRoot => ROChildList => ROChild
or even
RORoot => ROChildList => ROChild
On the other hand, I couldn't MarkAsChild (using CSLA.NET 4.0.1) ReadOnlyListBase (didn't try for ReadOnlyBase).
Regards
Hi,
A child and lazy loaded object will have the Fetch operation af a root object (using a static Get method with DataPortal.Fetch<T>) but return child objects.
A child object that loads within the root object will use the Child_Fetch method.
So the relationship flags does not control how the child objects are loaded.
RelationshipTypes.LazyLoad:
If FieldManager.FieldExists returns false and you try to get the value - then FieldManager will throw an Exception. It is a logical error to access the field before it has been initalized/loaded.
RelationshipTypes.Child
Use this to indicate that Field is not a value type - and will contain a child or child list object.
IIn reality there is no "child" concept with read-only objects.
The concept of a child is only important when doing insert/update/delete operations, because a child is persisted as part of its parent. But with read-only objects there's no save operation at all, so this idea of containment is not real meaningful.
This is part of why read-only objects are simpler and lighter weight than editable objects - there's a whole lot of stuff that just doesn't exist in ReadOnlyBase that does exist in BusinessBase (undo, persistence, business rules, metastate tracking, etc).
I suppose it could be argued that it should be allowed (and just ignored) to provide consistency.
After Jonny's answer, I think this would be a good idea.
Copyright (c) Marimer LLC