大家好,我正在从web api中获取并将其存储在var" obj1"中。然后将其添加到列表" snap"对象类型......我必须对" snap"执行操作所以列表应该按照一个参数升序排列,例如"距离" ....请帮帮我
这是我的代码..
List<object> snap = new List<object>();
var obj1 = objEntity.TB_Broadcast_Snap.Where(s => s.snapid == sid)
.Join(objEntity.TB_User_Registration,
u => u.userid,
v => v.userid,
(u, v) => new { TB_Broadcast_Snap = u, TB_User_Registration = v })
.Select(s => new
{
s.TB_Broadcast_Snap.snapid,
s.TB_Broadcast_Snap.title,
s.TB_Broadcast_Snap.details,
s.TB_Broadcast_Snap.category,
s.TB_Broadcast_Snap.tag,
s.TB_Broadcast_Snap.broadcastdistance,
s.TB_Broadcast_Snap.images,
s.TB_Broadcast_Snap.latitude,
s.TB_Broadcast_Snap.longitude,
s.TB_Broadcast_Snap.image_detail1,
s.TB_Broadcast_Snap.image_detail2,
s.TB_Broadcast_Snap.image_detail3,
s.TB_Broadcast_Snap.barcode_image,
s.TB_Broadcast_Snap.broadcast_date,
s.TB_Broadcast_Snap.promocode,
snaptitle = s.TB_Broadcast_Snap.title,
s.TB_Broadcast_Snap.broadcasttype,
s.TB_Broadcast_Snap.regionname,
distance = 0,
popcountno = popcount,
issnaped = issnapped,
//Vendor Detail
s.TB_User_Registration.emailid,
address1 = "No address",
s.TB_User_Registration.userid,
s.TB_User_Registration.username,
s.TB_User_Registration.imageurl,
s.TB_User_Registration.business_name,
s.TB_User_Registration.vendortype,
vendorname = s.TB_User_Registration.name,
}).ToList();
snap.AddRange(obj1);
答案 0 :(得分:1)
这是首先按Distance
订购,然后按另一个字段降序的方式:
var obj1 = objEntity.TB_Broadcast_Snap.Where(s => s.snapid == sid)
.Join(/*code*/)
.Select(/*code*/)
.OrderBy(item => item.Distance)
.ThenByDescending(item => item.OtherField)
.ToList();