我想获得Id,但我只有名称。 我的代码如下所示:lambda表达式
var comments = new List<Comments>
{
new Comments{
CommunityId = community.FirstOrDefault(comid => comid.IdCommunity.Where(comid.CommunityName == "TestCommunity")),
}
};
评论是一类:
public class Comments
{
public int IdComment { get; set; }
public DateTime Timestamp { get; set; }
public string Text { get; set; }
public int UserId { get; set; }
public int CommunityId { get; set; }
}
社区以及:
public class Community
{
public int IdCommunity { get; set; }
public string CommunityName { get; set; }
public Pictures Picture { get; set; }
}
但是,在C#中是不能接受的。 我需要做什么?
定义*不接受*。编译时出错?你有'使用System.Linq;'坐在上面? –
你能提供什么社区? – ad1Dima
'Where'返回一个集合,但'FirstOrDefault'需要一个'bool'。你可能想要使用'Any'而不是'Where',或者在'Where'后面链接'FirstOrDefault'。正是这取决于'community'和'comid'是什么。 – Abion47