2012-01-25 17 views
0

我想實現電子郵件功能,用戶可以發送電子郵件給20天后還沒有登錄的配置文件,也希望每10天后重複一次。有三張表的Linq Query在x天后加入發送提醒

I have three tables 
    1) "details" table where profile is maintained. 
    2) "notify" table where i keep a track of notification send to profiles. 
    3) "profile" table where i keep track of the login information of profile. 

到目前爲止,我已經試過這 -

list = (from c in ctx.details.AsEnumerable() 
         join u in ctx.profile.AsEnumerable() 
         join a in ctx.notify..AsEnumerable() 
         on c.profileid equals u.profileid equals a.profileid 
         where (u.last_login_date == null && 
         (DateTime.Now - u.last_login_date).TotalDays >= 20) 
         select new details 
         { 
          profileid = c.profileid.ToString(), 
          firstname = c.firstname, 
          lastname = c.lastname, 
          email = c.email 

         }).ToList(); 
  • My tables are -> 
        details    notify    profile 
        -----------  ------------   -------------- 
        profileid   profileid    profileid 
        firstname   alert_date(datetime) last_login_date(datetime) 
        lastname 
        email 
    

其中alert_date是,如果他之前已經發送電子郵件和last_login_date是 日期時的日期他最後登錄了個人資料。

但我相信這是行不通的。我希望細節表能夠充滿細節。 幫幫我。

+0

您沒有解決方案@ stian.net? –

回答

1

這裏是一個查詢,應該返回您的詳細信息對象的每一個一直沒有在20天內登錄或之後每10天增量(例如30天,40天)的輪廓。

list = (from c in ctx.detail 
     join u in ctx.profile 
     on c.profileid equals u.profileid 
     join a in ctx.notify 
     on c.profileid equals a.profileid 
     let datediff = DateTime.Now.Subtract(u.last_login_date).TotalDays 
     where datediff >= 20 && datediff % 10 == 0 
     select c).ToList(); 

我已刪除了AsEnumerable電話,因爲它是一件好事,讓數據庫做大量的工作,因爲它可以。它不在我的頭頂,未經測試,所以仍然可能存在一些錯誤,但這應該是一個很好的起點。

+1

如果您需要任何其他信息,請不要忘記,您可以通過將'select c'結尾更改爲'select new {Property1 = ,Property2 = }'來創建匿名類型。 – SPFiredrake

+0

@SPFiredrake是絕對正確的。我刪除了原始的匿名類型,因爲它是來自'detail'實體的所有數據,但它可以輕鬆地添加回來。 – diceguyd30