简体   繁体   中英

How can I make a LINQ expression return into a class?

I have the following LINQ:

        var questionIds = _questionsRepository.GetAll()
            .Where(m => m.Problem != null &&
            m.Problem.SubTopic != null &&
            m.Problem.SubTopic.Topic != null &&
            m.Problem.SubTopic.Topic.SubjectId == 1)
            .Select(m => m.QuestionId)
            .ToList();

Currently it does a select and returns a list of questionIds.

How can I change this LINQ so it returns a List

public class QuestionId
{
    public int QuestionId { get; set; }
}

创建一个QuestionId类的实例,并在Select内设置QuestionId属性,方法如下:

Select(m => new QuestionId { QuestionId = m.QuestionId })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM