【发布时间】:2014-08-25 03:57:28
【问题描述】:
我的 nHibernate 模型中有以下实体:
public class Customer : Entity {
public Customer () {
this.Notes = new List<Note>();
}
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
//....
public virtual ICollection<Note> Notes { get; set; }
}
public class Note : Entity {
public virtual Customer Customer { get; set; }
public virtual DateTime Timestamp { get; set; }
public virtual string Text { get; set; }
public virtual NoteType NoteType { get; set; }
}
public class NoteType : Entity {
public virtual string Description { get; set; }
public virtual string ShortCode { get; set; } //ie. "X", "Y", "Z"
}
在我的控制器中,我想返回在过去 24 小时内有特定类型备注的客户列表。所以 ShortCode 有一个特定的值。我的控制器如下所示:
public class MyController : Controller {
private IRepository<Customer> _repositoryCustomer;
private IRepository<Note> _repositoryNote;
public MyController (IRepository<Customer> repositoryCustomer, IRepository<Note> repositoryNote)
{
_repositoryCustomer = repositoryCustomer;
_repositoryNote = repositoryNote;
}
public ActionResult Index()
{
var notes = _repositoryNote.GetAll().Where(n => n.Timestamp > DateTime.Now.AddDays(-1) && n.NoteType.ShortCode == "X");
var customers = _repositoryCustomer.GetAll();
//change above to only return customers with note from past 24 hours that has a short code of "X"
//Not sure this is close to correct...
//var customers = _repositoryCustomer.GetAll().Join(notes, c => c.Id, note => note.Customer.Id, (customer, note) => customer).ToArray();
//but throws exception "Specified method is not supported." Seems to be failing in nHibernate
return View(customers);
}
}
我需要做什么才能获得过去 24 小时内包含特定类型备注的客户列表?我的想法是使用 linq 或 IQueryable 方法,但我都在苦苦挣扎。谢谢!
【问题讨论】:
-
是否可以假设在 _repositoryCustomer.GetAll() 方法中为客户填充了收款备注?
标签: c# linq nhibernate iqueryable