当通过实体框架访问数据库我有三个可用的实体:LINQ:过滤子对象
- stt_dictionary
- stt_concept
- stt_term
每个实体具有收藏第四个实体stt_change_log。
因此,例如,
stt_dictionary.stt_change_log = ICollection<stt_change_log>
那些顶部3元件和stt_change_log之间的关系是
stt_change_log.element_id = (stt_dictionary | stt_concept | stt_term).id;
然而,如stt_dictionary,stt_concept和stt_term都有INT作为它们的ID类型,还需要以下内容:
stt_change_log.element_type_id = (7 | 8 | 9)
现在,当我运行下面的查询语句时,它会返回所有具有指定ID的stt_change_log实体,这意味着如果我想在stt_dictionary.id = 1时需要stt_change_log实体,则还会获得stt_change_log条目,这些条目属于stt_concept和stt_term实体ID也= 1。换句话说,stt_change_log集合需要额外的过滤。
var daoDictionary = (from d in db.stt_dictionary
.Include("stt_change_log.stt_change_types")
where d.id == id
select d).FirstOrDefault();
我怎么能由stt_change_log集合中的element_type_id财产指定为每个项目的值过滤stt_change_log实体?
我还会补充一点,我的意图是在单个查询中执行此操作。
感谢您的快速响应,埃里克。我其实并不需要第一个。包括声明,因为该级别的儿童由一个协会填充。但是,即使stt_change_log和stt_change_types之间存在关联,stt_change_log也是如此。stt_change_type属性不会自动填充(我不知道为什么)。 因此,因为.Include语句仅用于下一级(不是我想要筛选的级别),所以这对我有利吗?这是否意味着*有*我可以在stt_change_log集合上做的事情? – awj 2013-03-26 17:39:05