惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
J
Java Code Geeks
H
Help Net Security
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
U
Unit 42
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 叶小钗
D
Docker
量子位
P
Proofpoint News Feed
博客园_首页
T
Tailwind CSS Blog
F
Fortinet All Blogs

博客园 - 不搽雪花膏

linux网关设置 <!DOCTYPE>标签与table高度100% (转) linux运行apache出现403错误 Ubuntu 12.10 Tty (字符终端) 显示中文,和字体大小设置 64位系统下组件服务的查看 转 Web前端性能优化全攻略 Castle ActiveRecord 笔记 - 不搽雪花膏 WQL测试工具 [转载]HttpModule与HttpHandler详解 转载 云计算七问七答 [转]整理.net程序集加载方法 MySQL(5.0)导出导入 .NET代码编写规范 Hibernate配置参数 [转]PKCS 证书 细数.net3.0的各项新特性 Jquery示例 Jquery入门 [转]Response.End、Response.Redirect 或 Server.Transfer 方法与 ThreadAbortException 异常
ActiveRecord返回部分字段的查询
不搽雪花膏 · 2011-12-13 · via 博客园 - 不搽雪花膏

1. 自定义非受管实体类

namespace IOT{

  public class CustomerProjection{

    public int ID = 0;

    public string Name = "";
    public CustomerProjection(int id, string name){

      ID = id;

      Name = name;
    }

  }

}

2. 在实体类属性添加对自定义非受管实体类的引入

[Imprt(typeof(IOT.CustomerProjection), "CustomerProjection")]

[ActiveRecord("Customers")]

public class Customer : ActiveRecordBase<Customer>

{

[PrimaryKey(PrimaryKeyType.Assigned)]

public string CustomerID

{

get { return customerID; }

set { customerID = value; }

}

.....

}

3. 在代码中用检索字段生成自定义非受管实体类

protected void Page Load(object sender, EventArgs e)

{

IActiveRecordQuery query = new HqlBasedQuery(typeof (Customer),

@"select new CustomerProjection(c.CustomerID, c.CompanyName)

from Customer c join c.Orders o where c.Country = 'USA'

group by c.CustomerID, c.CompanyName, c.City, c.Region

");

GridView1.DataSource = ActiveRecordMediator.ExecuteQuery(query);

GridView1.DataBind();

}