如何把这sql变为Linq查询

lilei_new 2012-06-15 10:15:51

select *
from drugpar d
where d.kind in (select [id] from optiondic o where o.name="xiyao")
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
UFO_O 2012-06-18
  • 打赏
  • 举报
回复
正在学习中...
wapjia43106140 2012-06-18
  • 打赏
  • 举报
回复
用SQL多好为什么非要用LIQ。好像以后不支持LIQ TO SQL啦吧
申江渔夫 2012-06-15
  • 打赏
  • 举报
回复
Contains<drugpar>(c.kind)
应该是Contains<int>(c.kind)吧
q107770540 2012-06-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
SQL code

select *
from drugpar d
where d.kind in (select [id] from optiondic o where o.name="xiyao")
[/Quote]
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;
lilei_new 2012-06-15
  • 打赏
  • 举报
回复

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
threenewbee 2012-06-15
  • 打赏
  • 举报
回复
var query = from x in drugpar
where optiondic.Where(y => y.name == "xiyao").Select(y => y.id).Contains(x.kind);

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧