我需要使用NHibernate从DB返回指定Date的ACC_INTERVAL_ID属性值列表以获取可用的时间间隔。 NHibernate版本是2.1.2.4000
AccreditationRecord:
public class AccreditationRecord : DomainObject
{
public AccreditationRecord()
{
Date = DateTime.Now;
}
/// <summary>
/// Интервал встречи
/// </summary>
public virtual AccreditationTimeIntervalEnum Interval { get; set; }
/// <summary>
/// Дата встречи
/// </summary>
public virtual DateTime Date { get; set; }
/// <summary>
/// Название компании
/// </summary>
public virtual string CompanyTitle { get; set; }
/// <summary>
/// Название выставки
/// </summary>
public virtual string ExhibitionTitle { get; set; }
/// <summary>
/// Комментарий аккредитируемого к форме
/// </summary>
public virtual string Comment { get; set; }
}
映射:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Mvk.Kvc.Domain" assembly="Mvk.Kvc.Domain">
<class name="AccreditationRecord" table="KVC_ACCREDITATIONS" lazy="false" >
<id name="ID" column="ID_ACCREDITATIONS" type="Int32" unsaved-value="-1">
<generator class="identity"/>
</id>
<property name="Date" column="ACC_DATE" type="DateTime" />
<property name="CompanyTitle" column="COMPANYTITLE" type="AnsiString" length="512" />
<property name="ExhibitionTitle" column="EXHIBITIONTITLE" type="AnsiString" length="512" />
<property name="Comment" column="COMMENT" type="AnsiString" length="1000" />
<property name="Interval" column="ACC_INTERVAL_ID" type="AccreditationTimeIntervalEnum" />
</class>
</hibernate-mapping>
我在存储库中的方法:
public virtual IList<int> GetFilledIntervals(DateTime selectedDate)
{
DetachedCriteria query = DetachedCriteria
.For(typeof(AccreditationRecord));
query.Add(Restrictions.Eq("Date", selectedDate));
query.SetProjection(Projections.Id());
return ??????????
}
答案 0 :(得分:0)
使用HN3:
public virtual IList<int> GetFilledIntervals(DateTime selectedDate)
{
IList<int> result =
session.QueryOver<AccreditationRecord>()
.Where(ar => ar.Date == selectedDate)
.Select(c => c.Id)
.List<int>();
return result;
}
答案 1 :(得分:0)
public virtual IList<int> GetFilledIntervals(DateTime selectedDate)
{
DetachedCriteria query = DetachedCriteria
.For(typeof(AccreditationRecord))
.SetProjection(Projections.Property("Interval"));
query.Add(Restrictions.Eq("Date", selectedDate));
return List<int>(query);
}