单个或多个Linq2sql存储库 [英] Single vs. multiple Linq2sql repositories
问题描述
我有一个Users表,Events表和一个UserEvents映射.在代码的某些部分,我只需要基于用户的内容.在其他部分,我需要所有这些信息. (特别是:给定用户,他们订阅的每个事件的详细信息是什么?)
I have a Users table, Events table, and a mapping of UserEvents. In some parts of my code, I just need user-based stuff. In other parts, I need all of this information. (Especially: given a user, what are the details of each event they are subscribed to?)
如果我有一个仅用于用户的存储库,而另一个用于用户+事件+ userevents的存储库,则自动创建的users对象将被复制,并且在我重命名其中一个之前,代码不会编译.这是可能的,但不方便.另一方面,如果我只有一个包含所有3个表的存储库,那么当我只想要用户信息时,由于linq获取具有该用户ID的所有关联数据会不会很昂贵?
If I have one repository just for users and another for users + events + userevents, then the auto-created users object is duplicated and the code won't compile until I rename one of them. This is possible but inconvenient. On the other hand, if I only have one repository with all 3 tables, when I just want user info, will it be expensive due to linq getting all the associated data with that user id?
在Linq2Sql中,如果在单个dbml/存储库中有更多表,它会更昂贵吗?
In Linq2Sql, is it more expensive if you have more tables in a single dbml/repository?
推荐答案
Linq2Sql使用延迟加载来获取其他信息.我相信可以将其配置为一次全部获取,但这不是默认行为.如果您要求用户,除非您特别要求他们,否则您将不会获得事件.
Linq2Sql uses lazy loading to get additional information. I believe it can be configured to fetch all at once, but that is not the default behavior. If you ask for a user, you will not get events unless you specifically ask for them.
这篇关于单个或多个Linq2sql存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!