业务逻辑视图VS code [英] Views with business logic vs code
问题描述
有关我需要发送个性化的邀请电子邮件给最终用户每隔一小时提出申请。这些用户电子邮件地址,和其信息的其余均在数据库中。
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.
- 有几分所有用户
Planned.IsPlannable
设置为真
和 有一个Planned.DateStart
和Planned.DateEnd
某间 期间可用于接收一 电子邮件。 - 有关于 350信息以发送每隔一小时
- 所有信息 必须包含在消息中 从数据库。
- 在该应用程序是 一个 .NET4.0控制台应用程序,进行数据 访问我使用 Subsonic3.0
- All users that have a bit
Planned.IsPlannable
set toTrue
and have aPlanned.DateStart
and aPlanned.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 :)查看是这样的:
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
和撰写,在此基础上考虑的结果,相应的消息在C#code 此应用程序。
and compose, based on the results of this view, the appropriate messages in the C# code of this application.
2 :) 撰写整个消息的SQL服务器在视图中,并返回类似
2:) Compose the entire message on the sql-server in the view and return something like
[EmailTo]
[Subject]
[Body]
那么只有遍历槽成果并建立 MailMessage
从中对象
在这两种情况下我得到的消息,如:
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
}
迭代低谷,在C#code和刚组成mailmessage从preformatted数据。
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?
更新:的确有文本操作中选择2。但是数据库,这是更换三根弦的messagbody到CompterName,DateStart和DateEnd.Perhaps,SQL-意见是足够聪明为s $ P $垫本的性能,而C#code做它时,请?
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"?
推荐答案
首先考虑的:你能更改邮件格式将成为必要的时候想象一个时间?如果没有,那么它可能并不重要。
First consideration: Can you envision a time when changing the emails format will become necessary? If not then it probably doesn't matter.
第二个考虑:你能想象当电子邮件将需要更多的操作比SQL很容易能够提供的时间呢?如果是这样,那么你绝对应该选择C#。
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?
最后一个备选方案:使用C#的邮件撰写,但使用一个数据库或基于文件的模板,可以很容易地被更新
And finally an alternative option: Use C# for the message composition, but use a database or file based Template that can easily be updated.
这篇关于业务逻辑视图VS code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!