I recently used base4.nethttp: // www.base4.net to develop an Account Management System, which defines a class of notecategory.
Public Class Notecategory
{
PublicItemcollection parents;//Target is source
}
The general XML schema is as follows:
<! -- Define form template type entity -->
< Typedef Fullname = "DGSoft. notemanagementalpha2.data. notecategory" Basename = "Maxtiviti. Storage. itembase" >
< Propertydef Name = "Title" Type = "String" Length = "100" Nullable = "False" />
< Relationshipdef Name = "Members" Type = "Maxtiviti. Storage. itembase" Relationshipname = "Notecategorymembers" Direction = "Linkissource" />
< Propertydef Name = "Copyright" Type = "String" Length = "200" Nullable = "True" />
< Propertydef Name = "Description" Type = "String" Length = "1000" Nullable = "True" />
< Relationshipdef Name = "Parents" Type = "DGSoft. notemanagementalpha2.data. notecategory" Relationshipname = "Notecategorymembers" Direction = "Linkistarget" />
</ Typedef >
Now, you need to query all typeof (notecategory) objects to meet the condition of parents. Count = 0;
However, objectpath "parents. count = 0 "or" parents [count] = 0 "cannot be queried, and an exception is thrown. Therefore, the forums of base4.net is used to ask. The result is as follows:
Ask (me ):
I defined a class "notecategory" that contains a attribute "parents"
The attribute is a collection
How to query the object typeof (notecategory) that parents. Count = 0 ?????
How to constuct the objectpath ??
Thanks very much !!!!
Answer: (Alex James)
I don't support embedding a count filter on a relationship in objectpath yet... Sorry.
Although what you are asking for shoshould be added... I will have a think about how in the next few days.
The problem is that I collapse callto object. relationship so that you are querying the related object not the actual relationship table.
What needs to be done is to add additional hardcoded filters to the object. relationship so that you can do the sort of things you are asking .... I will probably add support for this before beta3.
While you can't do it with object path you can do it...
If you use an objectcommand and write the SQL yourself.
Execute the objectcommand so it returns a reader (executereader) and Contruct an objectdatareader around the returned Reader so you can read your notecategory objects.
It depends how you defined your relationshipdef, if parent is defined with linkissource and a relationshipname = parent
This wowould return you all notecategories without parents:
Select * from [notecategory] Where id not in (select distinct (source) from [maxtiviti. Storage. Relationship] Where name = 'parent ')
When I get a chance I will post you a snippet on how to use this code with a objectcommand...
Haha, I really hope Alex can get out of beta3 soon. If I want to use the following solutions, there will be a lot of performance problems:
Public Itemcollection getallrootcategory ()
{
Itemcollection result = New Itemcollection ();
Itemcollection IC = Storagecontext. Find ( Typeof (Notecategory ), Null );
Foreach (Notecategory NC In Ic)
{
If(Nc. Parents. Count= 0)
Result. Add (NC );
}
Return Result;
}
although we can use the method proposed by Alex to write SQL statements, isn't that quite elegant?