C# 如何使用LINQ在列表中添加列表

C# 如何使用LINQ在列表中添加列表,c#,linq,wcf,list,C#,Linq,Wcf,List,我在WCF服务中找到了一个方法,返回一系列问题,这些问题还有一些选项(答案),可以选择 然后,这些选项将添加到客户端应用程序上的RadioButton列表中,以便客户端可以针对特定问题进行适当选择 我的问题是如何在返回到客户端应用程序的列表中添加列表 我想返回一个特定问题的选项列表 这就是我到目前为止所做的 public class ct_auditResults { private int AuditResultsID { get; set; } private int Que

我在WCF服务中找到了一个方法,返回一系列问题,这些问题还有一些选项(答案),可以选择

然后,这些选项将添加到客户端应用程序上的RadioButton列表中,以便客户端可以针对特定问题进行适当选择

我的问题是如何在返回到客户端应用程序的列表中添加列表

我想返回一个特定问题的选项列表

这就是我到目前为止所做的

public class ct_auditResults
{
    private int AuditResultsID { get; set; }
    private int QuestionID { get; set; }
    private string Question { get; set; }
    private string QuestionValue { get; set; }
    private int QuestionTypeID { get; set; }
    private bool IsOptional { get; set; }
    private bool AllowComments { get; set; }
    private bool AllowActions { get; set; }
    private List<QuestionOptionText> OptionText { get; set; }

    public int auditResultsID
    {
        get { return AuditResultsID; }
        set { AuditResultsID = value; }
    }

    public int questionID
    {
        get { return QuestionID; }
        set { QuestionID = value; }
    }

    public string question
    {
        get { return Question; }
        set { Question = value; }
    }

    public string questionValue
    {
        get { return QuestionValue; }
        set { QuestionValue = value; }
    }

    public int questionTypeID
    {
        get { return QuestionTypeID; }
        set { QuestionTypeID = value; }
    }

    public bool isOptional
    {
        get { return IsOptional; }
        set { IsOptional = value; }
    }

    public bool allowComments
    {
        get { return AllowComments; }
        set { AllowComments = value; }
    }

    public bool allowActions
    {
        get { return AllowActions; }
        set { AllowActions = value; }
    }

    public List<QuestionOptionText> optionText
    {
        get { return OptionText; }
        set { OptionText = value; }
    }


    public class QuestionOptionText
    {
        private string QuestionText { get; set; }

        public string questionText
        {
            get { return QuestionText; }
            set { QuestionText = value; }
        }
    }
}

class AuditResultsClass : IAuditResults
{
    CTDBDataContext db = new CTDBDataContext();

    public List<ct_auditResults> getQuestionsForSubSectionAudit(long _SiteAuditID, long _SubSectionID)
    {
        List<ct_auditResults> QuestionList = (from ar in db.AuditResults
                                                join q in db.Questions on ar.QuestionID equals q.QuestionID
                                                join qt in db.QuestionTypes on q.QuestionTypeID equals qt.QuestionTypeID
                                                join opt in db.Options on q.QuestionID equals opt.QuestionID
                                                where ar.SiteAuditID == _SiteAuditID &&
                                                    ar.SubSectionID == _SubSectionID
                                                select new ct_auditResults
                                                {
                                                    auditResultsID = ar.SiteAuditID,
                                                    questionID = ar.QuestionID,
                                                    questionValue = ar.QuestionValue,
                                                    questionTypeID = q.QuestionTypeID,
                                                    question = q.Question1,
                                                    isOptional = q.IsOptional,
                                                    allowComments = q.AlowComments,
                                                    allowActions = q.AllowActions,
                                                    // I would like to return the option list List<QuestionOptionText> OptionText
                                                }).ToList();
        return QuestionList;
    }
}
公共类ct\U审核结果
{
私有int AuditResultsID{get;set;}
private int QuestionID{get;set;}
私有字符串问题{get;set;}
私有字符串QuestionValue{get;set;}
private int QuestionTypeID{get;set;}
私有布尔等民族{get;set;}
私有布尔允许元素{get;set;}
私有布尔允许操作{get;set;}
私有列表选项文本{get;set;}
公共int auditResultsID
{
获取{return AuditResultsID;}
设置{AuditResultsID=value;}
}
公共int问题ID
{
获取{return QuestionID;}
设置{QuestionID=value;}
}
公共字符串问题
{
获取{返回问题;}
设置{Question=value;}
}
公共字符串值
{
获取{return QuestionValue;}
设置{QuestionValue=value;}
}
公共int问题类型ID
{
获取{return QuestionTypeID;}
设置{QuestionTypeID=value;}
}
公共图书馆
{
获取{return IsOptional;}
设置{IsOptional=value;}
}
公共场所允许使用的物品
{
获取{return AllowComments;}
设置{AllowComments=value;}
}
公共布尔许可
{
获取{return AllowActions;}
设置{AllowActions=value;}
}
公共列表选项文本
{
获取{return OptionText;}
设置{OptionText=value;}
}
公共类问题OptionText
{
私有字符串QuestionText{get;set;}
公共字符串文本
{
获取{返回问题文本;}
设置{QuestionText=value;}
}
}
}
类AuditResultClass:IAAuditResults
{
CTDBDataContext db=新的CTDBDataContext();
public List getQuestionsForSubSectionAudit(长站点审核,长子分区ID)
{
List QuestionList=(来自db.AuditResults中的ar
在db中加入q。ar上的问题。QuestionID等于q.QuestionID
在q上的db.QuestionTypes中加入qt。QuestionTypeID等于qt.QuestionTypeID
加入opt-in数据库。q.QuestionID上的选项等于opt.QuestionID
其中ar.SITEAUDID==\U SITEAUDID&&
ar.SubSectionID==\u SubSectionID
选择新的ct\U审核结果
{
auditResultsID=ar.SiteAudited,
questionID=ar.questionID,
questionValue=ar.questionValue,
questionTypeID=q.questionTypeID,
问题1,
等民族=q.等民族,
allowComments=q.AlowComments,
allowActions=q.allowActions,
//我想返回选项列表OptionText
}).ToList();
返回问题列表;
}
}

提前感谢。

您可以通过以下方式展开选择:

select new ct_auditResults
{
  ....
  optionText = some_query.ToList()
}

假设该表名为
QuestionOptionText
。然后你可以这样做:

question = q.Question1,
isOptional = q.IsOptional,
allowComments = q.AlowComments,
allowActions = q.AllowActions,
OptionText = db.QuestionOptionTexts
             .Where(w=>w.QuestionID==q.QuestionID)
             .Select(s=>new QuestionOptionText(){questionText=s.QuestionText})
             .ToList()
}).ToList();

制作一个带有答案的
问题,然后序列化并发送,不是更容易吗?或者,您将一个问题打包为一组5个“选项”,第一个选项实际上是问题,第二个选项是正确答案,在客户端洗牌,然后将其打包为
列表