Yeah, I'd seen that. Unfortunately, the sample would not compile for
me with AR 2.0. For future reference, here is a solution.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using NHibernate;
namespace CertifiedMailDomain
{
// Create a subclass of ActiveRecordBase with a property for each
// field returned from the query
[ActiveRecord]
public class DailyReport : ActiveRecordBase<DailyReport>
{
[PrimaryKey]
public DateTime SentDate { get; set; }
[Property]
public int Kount { get; set; }
public IList<DailyReport> GetDailyReport(DateTime fromDate,
DateTime toDate)
{
// Create your query, with the name or alias of each
resulting column
// matching one of the properties of the class
string query = @"select convert(date, Outgoing.SentDate)
as SentDate
, COUNT(*) as Kount
, DB_NAME() as DBName
from Envelope
, Outgoing
where Envelope.OutgoingId = Outgoing.Id
and Outgoing.SentDate between :fromDate
and :toDate
group by CONVERT(date, Outgoing.SentDate)
order by CONVERT(date, outgoing.SentDate)
desc";
return (IList<DailyReport>)
ActiveRecordMediator<DailyReport>.Execute(
(NHibernateDelegate) delegate(ISession session, object
instance)
{
return session.CreateSQLQuery(query)
.AddEntity(typeof(DailyReport))
.SetParameter("fromDate", fromDate)
.SetParameter("toDate", toDate)
.List<DailyReport>();
}, this);
}
public IList<DailyReport> GetDailyReport()
{
return this.GetDailyReport(DateTime.Parse("1/1/1900"),
DateTime.Parse("12/31/2099"));
}
}
}
Then, in your code-behind:
protected void Page_LoadComplete(object sender, EventArgs e)
{
UsageList.DataSource = new DailyReport().GetDailyReport();
UsageList.DataBind();
}
Then, in your aspx:
<asp:ListView ID="UsageList" runat="server">
<LayoutTemplate>
<table>
<thead>
<th>Date</th>
<th>Envelopes Sent</th>
</thead>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" /
>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<!--<td><%# Eval("SentDate") %></td>-->
<td><%# Eval("SentDate", "{0:d}") %></td>
<td><%# Eval("Kount") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
On Oct 17, 4:56 pm, Markus Zywitza <[email protected]> wrote:
> http://castleproject.org/activerecord/documentation/trunk/usersguide/...
> <http://castleproject.org/activerecord/documentation/trunk/usersguide/...>
> -Markus
>
> 2009/10/17 Chris Curvey <[email protected]>
>
>
>
> > Sometimes, I just want to run SQL, with all it's warts and features.
> > For example, I want to run this query against my database and just
> > splatter the results on the page:
>
> > select date(processed_date), count(*)
> > from foobar
> > group by date(processed_date)
> > order by date(processed_date) desc;
>
> > Can someone point me to the best way to go about doing this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---