速度相关问题 - (F)NHibernate

发布于 2024-11-30 12:38:05 字数 519 浏览 1 评论 0原文

我有一个 A 类,其中包含 B 列表:IList。这将 As 与 Bs 关联起来(映射为多对多关系)。 As 和 B 之间的关联由包含 B 的外部源确定。请注意,出于效率原因,我的数据库中有一份 Bs 副本。我有时必须运行一个脚本来确定属于特定 A 的所有 B。该脚本返回一些密钥,我可以使用这些密钥从存储库获取 B。

现在,每次运行此更新时,我都会清除 B 列表并通过我的存储库获取每个 B。这是非常低效的。我只是想知道是否可以做些什么来加快速度?

我尝试在这里使用 B 的 id 列表:

Fluent Nhibernate Problem

但我无法坚持由于某些无法解释的原因,我可能不得不再次使用“完全成熟”的实体列表,这没有问题,但有通过存储库一个接一个地获取每个实体的开销。

任何反馈将不胜感激。非常感谢。

最好的祝愿,

克里斯蒂安

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:

Fluent Nhibernate problem

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风苍溪 2024-12-07 12:38:05

对于这种情况,有 Session.Load

X.Blas.Add(Session.Load(bid));   // returns a proxy with initialized Id, almost the same as the id

,我认为 X.Blas.Clear(); 会比 X.Blas = new Iesi.Collections.Generic 更好.HashedSet();

编辑:要有效地加载多个 B,您还可以

var blist = Session.QueryOver<B>()
    .Where(b => b.Id.IsIn(IdList))
    .List();

进一步节省一些工作

foreach(var bid in idList)
{
    var b = Session.Load(bid);
    if (!x.SetOfBs.Contains(b))
        x.SetOfBs.Add(b);
}

for this case there is Session.Load

X.Blas.Add(Session.Load(bid));   // returns a proxy with initialized Id, almost the same as the id

and i think X.Blas.Clear(); would be better than X.Blas = new Iesi.Collections.Generic.HashedSet<B>();

Edit: to load multiple Bs efficiently you can also do

var blist = Session.QueryOver<B>()
    .Where(b => b.Id.IsIn(IdList))
    .List();

to further save some work you can

foreach(var bid in idList)
{
    var b = Session.Load(bid);
    if (!x.SetOfBs.Contains(b))
        x.SetOfBs.Add(b);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文