如何在linq中编写查询 [英] How do I write the query in linq

查看:92
本文介绍了如何在linq中编写查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 -



我想在linq中重写这个查询并且根本不知道。在我的应用程序中,我有强类型的视图模型,因此不知道是否使用了一些文章已经说明的一般类型。



这是sql:



Hi -

I'm looking to rewrite this query in linq and literally have no idea. In my application I have strongly typed view models so dont know if using annomous types as a few of the articles have stated.

Here is the sql :

select 
	o.ReplacementItemID,
	o.ItemStatus,
	o.Description,
	i.ItemWarrantyID,
	o.Id as OriginalItemId
from
	(
		select 
			id,
			ItemStatus,
			Description,
			ItemWarrantyID,
			ReplacementItemID
		from item
		where ItemStatus = 'obso'	
	)o
	inner join Item i	
	on o.ReplacementItemID = i.Id
	--where o.ReplacementItemID = 948032





我尝试过:



http://linq101.nilzorblog.com/linq101-lambda.php



What I have tried:

http://linq101.nilzorblog.com/linq101-lambda.php

推荐答案

var queryNestedGroups =

来自学生的学生

学生组学生。从newGroup2进入newGroup1

in

(来自newGroup1的学生

由student.LastName组学生)

group newGroup2 by newGroup1.Key;
var queryNestedGroups =
from student in students
group student by student.Year into newGroup1
from newGroup2 in
(from student in newGroup1
group student by student.LastName)
group newGroup2 by newGroup1.Key;


这篇关于如何在linq中编写查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆