select *
from drugpar d
where d.kind in (select [id] from optiondic o where o.name="xiyao") 

解决方案 »

  1.   

    var query = from x in drugpar
                where optiondic.Where(y => y.name == "xiyao").Select(y => y.id).Contains(x.kind);
      

  2.   


     public System.Data.Objects.DataClasses.EntityCollection<drugpar> GetKind()
            {
                using (HospitalEntities1 hospital = new HospitalEntities1())
                {
                    var query = from c in hospital.drugpar
                                where hospital.optiondic.Where(y => y.name == "xiyao").Select<optiondic, int>(y => y.id).Contains<drugpar>(c.kind)
                                select c;
                               
                }        }
        }错误 2 “System.Linq.IQueryable<int>”不包含“Contains”的定义,并且最佳扩展方法重载“System.Linq.Queryable.Contains<TSource>(System.Linq.IQueryable<TSource>, TSource)”的某些参数无效 D:\Program\His\drug\drug\optiondic.cs 18 28 Drug
      

  3.   

    var query= from d in hospital.drugpar
               let temp=hospital.optiondic.Where(o=>o.name=="xiyao").Select(o=>o.id)
               where temp.Contains(d.kind)
               select d;
      

  4.   

    Contains<drugpar>(c.kind)
    应该是Contains<int>(c.kind)吧
      

  5.   

    用SQL多好为什么非要用LIQ。好像以后不支持LIQ TO SQL啦吧