Subsonic How to select between date

*爱你&永不变心* 提交于 2019-12-11 07:45:52

问题


Could anyone tell me how to do the select function in SubSonic project to query all customer who will have birthday in next two week from today.

Table Customer Name Thomas DOB 19/09/1981

Thank you


回答1:


If you're only using one provider (most people are) and you want to take advantage of the table structs that SubSonic generates for you:

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>();



回答2:


Please try this:

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

PS:- Provider is your SubSonic provider name.




回答3:


I think I need to explain more on what's I would like to have, I would like to send an email to all customer who birthday is in the next 2 weeks in 3 times, 2 weeks before his/her birthday, 3 days before and 1 days before.




回答4:


In SQL Server, this would be something like

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

In SubSonic, you could write this like so:

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")


来源:https://stackoverflow.com/questions/994656/subsonic-how-to-select-between-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!