使用Base4.Net进行项目开发中的问题
2005-03-29 08:16
716 查看
最近在使用Base4.Nethttp://www.base4.net开发一个台帐管理系统,定义了一个类NoteCategory
public class NoteCategory
<!-- 定义表单模版类型实体 -->
<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>
现在查询的需求是查出所有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版啊,要不我用以下的解决方案,有很大的性能问题啊:
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;
}
虽然可以用alex提出的方法写Sql解决,但是那样做不是相当的不优雅的吗?
public class NoteCategory
<!-- 定义表单模版类型实体 -->
<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>
现在查询的需求是查出所有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版啊,要不我用以下的解决方案,有很大的性能问题啊:
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;
}
虽然可以用alex提出的方法写Sql解决,但是那样做不是相当的不优雅的吗?
相关文章推荐
- Android开发之搜芽项目的图片加载问题(使用Volley进行网络图片加载)
- 使用sun.net.ftp.FtpClient进行上传功能开发,在jdk1.7上不适用问题的解决
- 使用Intellij进行SpringMVC网站开发问题总结
- [Win8]如何使用Visual Studio2012进行Windows8项目开发
- 使用GDI+进行开发的一些问题(1)
- 使用GDI+进行开发的一些问题(3)
- 使用GDI+进行开发的一些问题(10)
- 解决eclipse MAVEN项目导入使用intellij idea开发target目录下不存在mapper.xml文件问题
- 【推荐】使用Jquery+EasyUI进行框架项目开发案例讲解之一---员工管理源码分享 推荐
- windows上使用eclipse远程连接hadoop进行程序开发没有权限访问问题
- 开发时遇到使用LINQ无法进行数据插入时的问题
- 用C#在MVC模式下进行Web项目开发,cshtml下三级联动下拉框获取初始值及传值显示的问题
- 使用 git 进行项目同步开发步骤
- 【项目搭建】使用spring-boot进行REST风格的微服务开发入门
- 好久不做开发了,最近使用vs2008遇到了不能添加多个项目的问题,在此标记一下
- 多语种开发项目使用oracle+PL/SQL Developer的韩文插入问题
- 使用vss2005在vs2005项目中进行协作开发
- 使用springMVC + Spring进行web开发时,aop不生效的问题
- 使用Jquery+EasyUI进行框架项目开发案例讲解之一---员工管理源码分享