每桌一个存储库或每个功能单元一个? [英] One repository per table or one per functional section?

查看:104
本文介绍了每桌一个存储库或每个功能单元一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC 2和C#与实体框架4.0至code反对规范化SQL Server数据库。我的数据库结构的一部分,包含了外键与子表含司机,汽车,发动机,底盘条目表等。

I am using ASP.NET MVC 2 and C# with Entity Framework 4.0 to code against a normalised SQL Server database. A part of my database structure contains a table of entries with foreign keys relating to sub-tables containing drivers, cars, engines, chassis etc.

我下面的书呆子晚餐教程,建立一个信息库晚餐是不够公平。难道我做的一个司机,一个发动机,一个用于汽车等还是我做一个大的一个项目?

I am following the Nerd Dinner tutorial which sets up a repository for dinners which is fair enough. Do I do one for drivers, one for engines, one for cars and so on or do I do one big one for entries?

这是该类型的工作,最好的做法?我还是新的编码此方法。

Which is the best practise for this type of work? I am still new to this method of coding.

推荐答案

我想真的没有单一的最佳实践这 - 这取决于你的编码风格,并为您的应用程序的要求。你一定可以创造系统中的每个实体类型的仓库 - 这会工作得很好。

I guess there's really no single "best practice" for this - it depends on your coding style and the requirements for your app. You definitely could create a repository for each entity type in your system - that'll work just fine.

在你的情况在这里,我可能会至少考虑为驱动程序库,以及可能的第二个汽车,发动机,底盘(因为这些是有点在专业领域一样 - 他们是相互关联的,他们属于在一起)。

In your case here, I would probably at least consider having a repository for drivers, and possibly a second one for cars, engines, chassis (since those are kinda in the same area of expertise - they're interconnected, they "belong" together).

不过。当然,如果汽车,发动机和底盘的单个存储库变得过于臃肿,你可以考虑将其分成三个独立的库

But: of course, if that single repository for cars, engine and chassis gets too bloated, you might consider breaking it up into three separate repositories.

我会尽量找库的数量之间的平衡 - 尝试组合在一起是什么逻辑上属于一起 - 而在这些资料库的方法数。五,十方法是好的 - 如果你说20,30或50的方法,你的资料库可能只是过大而笨重

I would try to find a balance between the number of repositories - try to group together what logically belongs together - and the number of methods on those repositories. Five, ten methods is okay - if you're talking 20, 30 or 50 methods, your repository might just be too big and unwieldy.

这绝对是一个建筑的决定,正因为如此,他们不是真的有很多确凿的事实来指导你 - 这是更多的是一种直觉和经验之类的话。如果你不具备必要的经验,但 - 去用一种方法,使用它,当你完成 - 再次看它用挑剔的眼光看:什么工作呢?它有什么不工作?然后在你的下一个项目,尝试一些其他的方法,并质疑其有效性,也将在项目结束。在生活和学习!

This is definitely an architectural decision, and as such, they're not really a lot of hard facts to guide you - it's more of a "gut feeling" and experience kind of thing. If you don't have that necessary experience yet - go with one approach, use it, and when you're done - look at it again with a critical eye and see: what worked about it? What about it didn't work? and then in your next project, try some other approach and question its validity, too, at the end of the project. Live and learn!

这篇关于每桌一个存储库或每个功能单元一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆