最近在使用Base4.Nethttp://www.base4.net开发一个台帐管理系统,定义了一个类NoteCategory

使用Base4.Net进行项目开发中的问题public class NoteCategory
{
使用Base4.Net进行项目开发中的问题    
public ItemCollection Parents; //Target is source
使用Base4.Net进行项目开发中的问题
    使用Base4.Net进行项目开发中的问题
使用Base4.Net进行项目开发中的问题}

大致的Xml Schema如下

使用Base4.Net进行项目开发中的问题<!-- 定义表单模版类型实体 -->
使用Base4.Net进行项目开发中的问题    
<TypeDef fullName="DGSoft.NoteManagementAlpha2.Data.NoteCategory" baseName="Maxtiviti.Storage.ItemBase">
使用Base4.Net进行项目开发中的问题        
<PropertyDef name="Title" type="string" length="100" nullable="false" />
使用Base4.Net进行项目开发中的问题        
<RelationshipDef name="Members" type="Maxtiviti.Storage.ItemBase" relationshipName="NoteCategoryMembers" direction="LinkIsSource" />
使用Base4.Net进行项目开发中的问题        
<PropertyDef name="Copyright" type="string" length="200" nullable="true" />
使用Base4.Net进行项目开发中的问题        
<PropertyDef name="Description" type="string" length="1000" nullable="true" />
使用Base4.Net进行项目开发中的问题        
<RelationshipDef name="Parents" type="DGSoft.NoteManagementAlpha2.Data.NoteCategory" relationshipName="NoteCategoryMembers" direction="LinkIsTarget" />
使用Base4.Net进行项目开发中的问题    
</TypeDef>


现在查询的需求是查出所有typeof(NoteCategory)的对象,满足Parents.Count = 0的条件;
但是发现使用ObjectPath "Parents.Count=0"或"Parents[Count]=0"都无法进行查询,还抛出了异常;于是就到了Base4.Net的Forums上去问,结果得到的答案是:

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 should be added... I will have a think about how in the next few days.
The problem is that I collapse calls to 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 for....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 would 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...


呵呵,真希望alex快出beta3版啊,要不我用以下的解决方案,有很大的性能问题啊:

使用Base4.Net进行项目开发中的问题public ItemCollection GetAllRootCategory()
{
使用Base4.Net进行项目开发中的问题            ItemCollection result 
= new ItemCollection();
使用Base4.Net进行项目开发中的问题            ItemCollection ic 
= StorageContext.Find(typeof(NoteCategory),null);
使用Base4.Net进行项目开发中的问题            
foreach(NoteCategory nc in ic)
{
使用Base4.Net进行项目开发中的问题                
if(nc.Parents.Count == 0)
使用Base4.Net进行项目开发中的问题                    result.Add(nc);
使用Base4.Net进行项目开发中的问题            }

使用Base4.Net进行项目开发中的问题            
return result;
使用Base4.Net进行项目开发中的问题        }

虽然可以用alex提出的方法写Sql解决,但是那样做不是相当的不优雅的吗?

相关文章:

  • 2021-09-12
  • 2021-08-08
  • 2021-06-28
  • 2022-12-23
  • 2021-08-22
  • 2021-04-16
  • 2021-05-15
  • 2021-06-25
猜你喜欢
  • 2021-08-25
  • 2021-09-04
  • 2022-12-23
  • 2022-02-18
  • 2021-11-04
  • 2021-08-15
相关资源
相似解决方案