包括一组过滤的记录

时间:2012-05-21 18:42:45

标签: c# asp.net-mvc-3 linq entity-framework-4.1 lazy-loading

这可能吗?

var results = (from c in _context.properties
               where c.strap == somevalue
               select c).include("characteristics).where(characteristics.cat_cd != 'DD');

基本上我想创建这个查询。随着应用程序的增长,我将包括其他表格。

select * from properties p,characteristics c
where 
p.strap = c.strap
and c.cat_cd <> 'DD'

2 个答案:

答案 0 :(得分:0)

您只需制作join声明:

var set = from property in _context.Properties
          join characteristic in _context.Characteristcs on property.strap equals characteristic.strap
          select new 
          {
              Property = property,
              Characteristic = characteristic
          }

答案 1 :(得分:0)

这是我学到的东西。

var results = (from c in _context.properties
               where c.Characteristics.Any(c=>c.cat_cd == "DD") select c);