存储过程的设计问题
我正在构建某种内容系统。
无论如何,我有一个包含 3 个表的数据库 假设一个用于新闻,其他用于文章和故事。
现在我想提供一项服务,仅备份将要编辑的文章。 无论如何,我想要 ASP.NET 中的所有逻辑,而不是数据库本身。
无论如何,我的问题从这里开始:我的存储过程插入了我想要使用的新文章,将这些文章插入到 tbl_articles 表中 现在我想使用我的业务层,它使用我的数据层 调用该存储过程将备份的文章插入到名为的表中 tbl_articles_backup
现在我发现我有一个设计问题...也许如果我过去在开始时考虑过这个功能,我会在我的数据层中使用其他东西,比如 linq 或类似的东西。
现在我的问题是:我该怎么做才能在不改变所有程序的情况下仍然获得最好的设计。 我不想重复相同的存储过程..并且我不想只重载业务层和数据层中的方法。
有什么想法吗?... 我最好的选择是什么?
谢谢
i am building some sort of content system.
anyway i have a database with 3 tables
lets say one is for news and the others for articles and stories.
now i want to make a service which backups only articles who are going to get edited.
anyway i want all the logic in the asp.net and not in the database itself.
anyway my problem starts here: the stored procedures i have that inserts new articles which i want to use inserts those articles to the tbl_articles table
and now i want to use my buisness layer which uses my data layer
that calls that stored procedure to insert backed up articles to a table called
tbl_articles_backup
now i see i have a design problem... maybe if i have thought about this feature in the past when i started i would of used something else like linq or something like that in my data layer.
now my question is : what can i do in oreder to still get the best design i can without changing the all program.
i dont want to duplicate the same stored procedure.. and i dont want to just overload the methods in the buisness layer and the data layer.
any ideas?..
whats my best option?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为触发器是你最好的选择。每当表更新时,它都可以将同一行插入到备份表中。这是自动的,并保证在您的交易期间运行。
其实没那么难。最后,如果您使用 VB 或 SQL 编写逻辑,您仍然需要学习 LINQ 或 SQL 命令。我个人建议尝试将数据库逻辑保留在数据库中并简化 ASP.NET 方面的事情。
如果您给我们一份插入 SP 的副本,我可以向您展示如何编写更新触发器。
I think a trigger is your best choice. Anytime the table gets updated it can insert the same row into your backup table. This is automatic and guaranteed to run during your transactions.
Its not really that hard. In the end if you write your logic in VB or SQL you will still need to learn LINQ or SQL commands. I personally recommend trying to keep the database logic in the database and simplify the asp.net side of things.
If you give us a copy of the insert SP I can show you how to write the update trigger.
“无论如何,我想要 ASP.NET 中的所有逻辑,而不是数据库本身。...
我
最好的选择是什么?”
好吧,如果你已经决定你想要你的逻辑在数据库之外,那么无论你要求什么“选项”,都只是 asp.net 选项,绝对不是数据库/dbms 选项,你最好删除其中任何一个“数据库”标签。
"anyway i want all the logic in the asp.net and not in the database itself.
...
whats my best option?"
Well, if you are already decided that you want your logic outside of the database, then whatever 'options' you are asking for, are merely just asp.net options and definitely not database/dbms options, and you had better remove any of those 'database' tags.