速度相关问题 - (F)NHibernate
我有一个 A 类,其中包含 B 列表:IList。这将 As 与 Bs 关联起来(映射为多对多关系)。 As 和 B 之间的关联由包含 B 的外部源确定。请注意,出于效率原因,我的数据库中有一份 Bs 副本。我有时必须运行一个脚本来确定属于特定 A 的所有 B。该脚本返回一些密钥,我可以使用这些密钥从存储库获取 B。
现在,每次运行此更新时,我都会清除 B 列表并通过我的存储库获取每个 B。这是非常低效的。我只是想知道是否可以做些什么来加快速度?
我尝试在这里使用 B 的 id 列表:
但我无法坚持由于某些无法解释的原因,我可能不得不再次使用“完全成熟”的实体列表,这没有问题,但有通过存储库一个接一个地获取每个实体的开销。
任何反馈将不胜感激。非常感谢。
最好的祝愿,
克里斯蒂安
I have a class A which contains a list of Bs: IList. This associates As with Bs (mapped as a many-to-many relationship). The association between As and Bs is determined by an external source which contains the Bs. Please note that I have a copy of Bs in my database for efficiency reasons. From time to time I have to run a script that determines all Bs that belong to a particular A. The script returns some keys that I can use to obtain the Bs from a repository.
Now each time I run this update I clear the list of Bs and get each B via my repository. This is very inefficient. I am just wondering whether there is anything I can do to make this faster?
I have tried to just use a list of ids of Bs here:
but I cannot persist the ids for some unexplained reason so I may have to use a list of ‘fully blown’ entities again, which is no problem but has this overhead of obtaining each entity one after another via the repository.
Any feedback would be very much appreciated. Many thanks.
Best wishes,
Christian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这种情况,有 Session.Load
,我认为 X.Blas.Clear(); 会比 X.Blas = new Iesi.Collections.Generic 更好.HashedSet();
编辑:要有效地加载多个 B,您还可以
进一步节省一些工作
for this case there is
Session.Load
and i think
X.Blas.Clear();
would be better thanX.Blas = new Iesi.Collections.Generic.HashedSet<B>();
Edit: to load multiple Bs efficiently you can also do
to further save some work you can