Castle 中ActiveRecord查询部分字段属性的投影(Projections)使用教程
2009-04-27 16:27
423 查看
Castle 中ActiveRecord查询部分字段属性的投影(Projections)使用教程
很多 Castle ActiveRecord系列教程都没有介绍投影(Projections)的使用,这里我用代码举例下....
查询部分字段属性..很方便灵活...同时效率也提高很不少..特别是大表多字段的情况下...(问题咨询QQ1163551688)
[Test]
public void ScalarProjectionQueryTest()
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
ScalarProjectionQuery<Blog, int> proj = new ScalarProjectionQuery<Blog, int>(Projections.RowCount());
int rowCount = proj.Execute();
Assert.AreEqual(1, rowCount);.(问题咨询QQ1163551688)
}
[Test]
public void UnTypedProjectionQueryTest()
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
ProjectionQuery<Blog> proj = new ProjectionQuery<Blog>(
Projections.ProjectionList()
.Add(Projections.Property("Name"))
.Add(Projections.Property("Author")));
IList<object[]> results = proj.Execute();
Assert.AreEqual(blog.Name, results[0][0]);
Assert.AreEqual(blog.Author, results[0][1]);.(问题咨询QQ1163551688)
}
[Test]
public void TypedProjectionQueryTest()
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
ProjectionQuery<Blog, KeyValuePair<string, string>> proj = new ProjectionQuery<Blog, KeyValuePair<string, string>>(
Projections.ProjectionList()
.Add(Projections.Property("Name"))
.Add(Projections.Property("Author")));
IList<KeyValuePair<string, string>> results = proj.Execute();
Assert.AreEqual(blog.Name, results[0].Key);
Assert.AreEqual(blog.Author, results[0].Value);.(问题咨询QQ1163551688)
}
很多 Castle ActiveRecord系列教程都没有介绍投影(Projections)的使用,这里我用代码举例下....
查询部分字段属性..很方便灵活...同时效率也提高很不少..特别是大表多字段的情况下...(问题咨询QQ1163551688)
[Test]
public void ScalarProjectionQueryTest()
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
ScalarProjectionQuery<Blog, int> proj = new ScalarProjectionQuery<Blog, int>(Projections.RowCount());
int rowCount = proj.Execute();
Assert.AreEqual(1, rowCount);.(问题咨询QQ1163551688)
}
[Test]
public void UnTypedProjectionQueryTest()
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
ProjectionQuery<Blog> proj = new ProjectionQuery<Blog>(
Projections.ProjectionList()
.Add(Projections.Property("Name"))
.Add(Projections.Property("Author")));
IList<object[]> results = proj.Execute();
Assert.AreEqual(blog.Name, results[0][0]);
Assert.AreEqual(blog.Author, results[0][1]);.(问题咨询QQ1163551688)
}
[Test]
public void TypedProjectionQueryTest()
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
ProjectionQuery<Blog, KeyValuePair<string, string>> proj = new ProjectionQuery<Blog, KeyValuePair<string, string>>(
Projections.ProjectionList()
.Add(Projections.Property("Name"))
.Add(Projections.Property("Author")));
IList<KeyValuePair<string, string>> results = proj.Execute();
Assert.AreEqual(blog.Name, results[0].Key);
Assert.AreEqual(blog.Author, results[0].Value);.(问题咨询QQ1163551688)
}
相关文章推荐
- ABAP--在查询条件只包含部分索引字段时,如何使用索引
- hibernate使用createQuery(hql)语句仅查询部分字段,应如何获得数据
- ABAP--在查询条件只包含部分索引字段时,如何使用索引
- Hibernate使用Criteria查询部分字段
- ActiveRecord返回部分字段的查询
- hibrenate使用select语句查询多张表的部分字段,并封装到一个实体类(无配置文件)中
- 使用mybatis,在添加数据的时候返回主键,当查询count和属性字段怎么接收返回数据
- SQL 部分函数的使用,子查询,group by,虚拟字段,case……
- Castle ActiveRecord学习实践(7):使用HQL查询
- ABAP--在查询条件只包含部分索引字段时,如何使用索引
- ABAP--在查询条件只包含部分索引字段时,如何使用索引
- ABAP--在查询条件只包含部分索引字段时,如何使用索引
- 使用hibernate中getHibernateTemplate查询部分字段
- 使用Fastjson生成Json字符串少字段属性(数据丢失)
- 富文本的使用之一 给TextView部分字段添加点击事件
- mysql -- 查询表所有字段的属性和注释
- Silverlight教程第七部分: 使用控件模板定制控件的观感
- Mybatis如何查询部分字段
- 微软Kinect for windows SDK 使用教程 (NUI部分)
- 使用公共静态属性的方式来代替公共静态字段(C#)