使用linq:查询赋予自定义对象
string _eventName = Request["Content"] ?? "";
var _userComment = from com in db.UserComment
join users in db.User on com.UserID equals users.Id
//join hd in db.table1 on com.EventID equals hd.ID
//where hd.HuoDongName.Contains(_eventName)
select new UserComments
{
ID = com.ID,
EventID = com.EventID,
UserID = com.UserID,
EventContent = com.EventContent,
UpQty = com.UpQty,
DownQty = com.DownQty,
InDateTime = com.InDateTime,
UserName = users.UserName//,hd.HuoDongName
};
List<UserComments> comm = _userComment.ToList();
public class UserComments
{
public int ID { get; set; }
public int Event { get; set; }
//.....
public UserComments(int Id, int eventID)
{
this.ID = Id;
this.Event = eventID;
}
}
go on
var _even = from hd in db.table1
orderby hd.ID descending
select new NameValue { Value = hd.ID, Name = hd.HuoDongName };
huoDongList = _even.ToList();
var _user = from user in User
where user.Status==1
select new NameValue { Value = user.Id, Name = user.NickName };
userList = _user.ToList();