C#.Net:List集合列表的Linq语句查询示例

1、单个List集合列表查询:

//筛选用户名、密码相符的用户
var resultList = from item in selectList
                 where item.PUsername.ToLower() == loginEntity.Username.ToLower() && item.PLoginPswd ==loginEntity.Password
                 select item;
var escortList = resultList.ToList();


 2、多个List集合列表关联查询: 

var results = from itemDispatch in dispatchList
	join itemDispatchEscort in dispatchEscortList
	on itemDispatch.PID equals itemDispatchEscort.PDispatchID
	orderby itemDispatch.PAssignedTime ascending
	select new DispatchResponseEntity
	{
		ID = itemDispatch.PID.Value,
		TransportType = itemDispatch.PTransportType,
		Status = itemDispatch.PStatus,
		PatientName = itemDispatch.PPatientName,
		FromRoom = itemDispatch.PFromRoomName,
		FromBed = itemDispatch.PFromBed,
		ToRoom = itemDispatch.PToRoomName,
		ToBed = itemDispatch.PToBed,
		DispatchEquipment = itemDispatch.PDispatchEquipment,
		RequestedTime = itemDispatch.PRequestedTime.Value.ToString("yyyy-MM-dd HH:mm:ss"),
		AssignedTime = itemDispatch.PAssignedTime.Value.ToString("yyyy-MM-dd HH:mm:ss"),
		NeededTime = itemDispatch.PNeededTime.Value.ToString("yyyy-MM-dd HH:mm:ss"),
		Priority = itemDispatch.PPriorityDesc,
		Remarks = itemDispatch.PDispatchDesc
	};
var resultList = results.ToList();


注意这个DispatchResponseEntity实体是自定义的。可定义自己想返回的实体类型:属性自定义。

 

(完)

2012年11月14日

Kevin.Chen  苏州太仓

O(∩_∩)O~

 

 

你可能感兴趣的:([02]ASP.NET,[01]C#&编程)