亚音速如何在日期之间进行选择

时间:2009-06-15 06:02:02

标签: select subsonic

有人能告诉我如何在SubSonic项目中执行选择功能,以查询将在未来两周内生日的所有客户。

表客户 姓托马斯 DOB 19/09/1981

谢谢

4 个答案:

答案 0 :(得分:5)

如果您只使用一个提供商(大多数人),并且您想利用SubSonic为您生成的表格结构:

CustomerCollection customers = DB.Select().From(Customers.Schema)
  .Where(Customers.Columns.CustomerName).IsEqualTo("Thomas")
  .And(Customers.Columns.DOB).IsBetweenAnd(DateTime.Today, DateTime.Today.AddDays(14))
  .ExecuteAsCollection<CustomerCollection>();

答案 1 :(得分:0)

请试试这个:

new Select("Provider").From("Customers")
.Where("CustomerName")
.IsEqualTo("Thomas")
.Where("DOB")
.IsBetweenAnd(DateTime.Today, DateTime.Today.AddDays(14));

PS: - 提供商是您的SubSonic提供商名称。

答案 2 :(得分:0)

我想我需要更多地解释一下我想拥有什么,我想发送电子邮件给所有在接下来的两周内生日3次,生日前2周,3天的客户之前和之前的1天。

答案 3 :(得分:0)

在SQL Server中,这类似于

select name, dob 
from customer
where datediff(day,getDate(),dob)+1 = 14 
or datediff(day,getDate(),dob)+1 = 3
or datediff(day,getDate(),dob)+1 = 1

在SubSonic中,您可以这样写:

new Select(Customer.NameColumn, Customer.DobColumn)
.From(Customer.Schema)
.Where("datediff(day,getDate(),dob)+1=14")
  .Or("datediff(day,getDate(),dob)+1=3")
  .Or("datediff(day,getDate(),dob)+1=1")