LINQ多对多关系:解决方案? [英] LINQ many-to-many relationships: Solution?

查看:82
本文介绍了LINQ多对多关系:解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,LINQ一直非常出色,但是执行基本的m2m查询没有提供我可以立即看到的解决方案.

LINQ so far has been remarkably elegant, but to perform basic m2m queries it offers no solution I can imediately see.

更糟糕的是,尽管LINQ可以用于任何其他表关系,但在我的m2m表的类结构中却没有给我关联.

What's worse is that while it works for any other table relationship, LINQ is not giving me an association in the class structure for my m2m table.

所以我可以做

artwork.artists.where(...)
//or
artist.Artworks.add(artwork)

但我做不到

artwork.artowrks_subjects.tagSubjects.where(...)
//or
tagSubject.artworks_subjects.add(artwork)

替代文本http://img299.imageshack.us/img299/257/20090902122107 .png

有解决此限制的通用模式吗?

Is there a common pattern for solving this limitation?

推荐答案

我自己找到了解决方案.为了使自动关系正常工作,两个表都需要主键(哎呀).请注意,artworks_subjects缺少PK符号.

Found the solution myself. For automated relationships to work, both tables need primary keys (oops). Notice artworks_subjects is missing the PK symbol.

这篇关于LINQ多对多关系:解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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