具有业务逻辑的视图与代码

发布于 2024-11-16 01:40:12 字数 1734 浏览 1 评论 0原文

对于应用程序,我需要每小时向最终用户发送个性化邀请电子邮件。这些用户的电子邮件地址及其其余信息都在数据库中。

  • 所有有一点的用户 Planned.IsPlannable 设置为 True 并且 有一个 Planned.DateStart 和一个 Planned.DateEnd 之间的某个时间 期间可用于接收 电子邮件消息。
  • 每小时大约有350 条消息要发送。
  • 所有信息表明 必须包含在消息中的是 从数据库中。
  • 该应用程序是 .NET4.0 控制台应用程序,用于数据 访问 我使用Subsonic3.0

至少有两种方案可供选择:通过 1

:) 查看类似的内容检索适当的数据:

SELECT    [Computer].ComputerName, 
          [User].UserEmail, 
          [Planned].DateAvailable, 
          [Planned].DatePlanned
FROM      [Computer] 
INNER JOIN
          [Planned] ON [Computer.ComputerID] = [Planned.ComputerID] 
INNER JOIN
          [User] ON [Computer].UserID = [User].UserID
WHERE     (DATEDIFF(dd, GETDATE(), [Planned.DateAvailable]) < 10) 
          AND Planned.IsPlannable = 1

以及撰写,根据此视图的结果,适当的数据此应用程序C# 代码中的消息。

结构图

2:) 在视图中在 sql-server 上撰写整个消息并返回类似的内容

[EmailTo]
[Subject]
[Body]

然后仅迭代结果并从中创建 MailMessage 对象

在这两种情况下我都会收到如下消息:

foreach (vwGetInvitableComputer u in UserController.GetAllInvitableUsers())
{
    // where the usercontroller wraps the Subsonic logic.
    // the composition happens here
}

Iterate trough that in the C# code and just compose the mailmessage from that preformatted 数据。

选择什么场景对性能和资源来说是明智的?

更新:选项 2 中的数据库中确实存在文本操作。但是,这会将消息正文中的三个字符串替换为 CompterName、DateStart 和 DateEnd。也许 SQL 视图足够智能,可以传播性能,而 C# 代码是否“在请求时”?

For an application I need to send personalized invitation emails to end-users every hour. Those users email-addresses, and the rest of their information are in the database.

  • All users that have a bit
    Planned.IsPlannable set to True and
    have a Planned.DateStart and a
    Planned.DateEnd between a certain
    period are available for receiving an
    email message.
  • There are about 350 messages to sent every hour.
  • All information that
    must be included in the message is
    from the Database.
  • The application is
    a .NET4.0 Console application, for data
    access I use Subsonic3.0.

There are at least two scenarios to choose from: retrieving the appropriate data via a

1:) View something like:

SELECT    [Computer].ComputerName, 
          [User].UserEmail, 
          [Planned].DateAvailable, 
          [Planned].DatePlanned
FROM      [Computer] 
INNER JOIN
          [Planned] ON [Computer.ComputerID] = [Planned.ComputerID] 
INNER JOIN
          [User] ON [Computer].UserID = [User].UserID
WHERE     (DATEDIFF(dd, GETDATE(), [Planned.DateAvailable]) < 10) 
          AND Planned.IsPlannable = 1

and compose, based on the results of this view, the appropriate messages in the C# code of this application.

graph of the structure

2:) Compose the entire message on the sql-server in the view and return something like

[EmailTo]
[Subject]
[Body]

Then only iterate trough the results and create MailMessage Objects from it

in both cases I get the messages like:

foreach (vwGetInvitableComputer u in UserController.GetAllInvitableUsers())
{
    // where the usercontroller wraps the Subsonic logic.
    // the composition happens here
}

Iterate trough that in the C# code and just compose the mailmessage from that preformatted data.

What scenario is performance and resources wise to choose?

update: There is indeed text manipulation in the database in option 2. However, this is replacing three strings in the messagbody to the CompterName, DateStart and DateEnd.Perhaps, SQL-views are smart enough to spread the performance for this, while the c# code does it "when requested"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

洋洋洒洒 2024-11-23 01:40:12

第一个考虑因素:您能否想象有一天需要更改电子邮件格式?如果没有,那么可能并不重要。

第二个考虑因素:您能否想象有一天,电子邮件需要的操作量将超过 SQL 能够轻松提供的操作量?如果是这样,那么你绝对应该选择 C#。

第三个考虑因素:重新部署会给环境带来多大的问题?

最后还有一个替代选项:使用 C# 进行消息撰写,但使用可以轻松更新的基于数据库或文件的模板。

First consideration: Can you envision a time when changing the emails format will become necessary? If not then it probably doesn't matter.

Second consideration: Can you envision a time when the emails will require more manipulation than SQL is easily capable of delivering? If so then you definitely should choose C#.

Third consideration: How problematic would a redeploy be for the environment?

And finally an alternative option: Use C# for the message composition, but use a database or file based Template that can easily be updated.

旧时模样 2024-11-23 01:40:12

我会选择选项 2,使用视图或存储过程在服务器上编写发送电子邮件所需的所有信息。理想情况下,数据库调用应尽可能减少与服务器的往返次数。

I would choose option 2, composing all the information required to deliver the emails on the server either using a view or a stored procedure. Ideally database calls should result in the least number of round trips to the server as possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文