读书人

这条语句如何用linq 写

发布时间: 2012-01-09 21:05:42 作者: rapoo

这条语句怎么用linq 写

C# code
SELECT * FROM [News] as n1 inner join news_type as n2 on n1.news_type=n2.type_id


[解决办法]
News 实体中有 news_type这个字段么?

如果没有:

NewsDataContext nc=new NewsDataContext
var list= (from x in nc.News join y in nc.news_type on x.news_type equals y.type_id select new {x,y});

也可以这样:
class temp
{
public int newsId{get;set;}
public string news_type{get;set;}
}

IList<temp> list= (from x in nc.News join y in nc.news_type on x.news_type equals y.type_id select new temp{newsId=x.newsId, news_type=y.news_type}).ToList<temp>;

读书人网 >.NET

热点推荐