Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用linq从表1中获取其id位于表2中的名称_C#_Asp.net_Xml_Linq To Sql - Fatal编程技术网

C# 使用linq从表1中获取其id位于表2中的名称

C# 使用linq从表1中获取其id位于表2中的名称,c#,asp.net,xml,linq-to-sql,C#,Asp.net,Xml,Linq To Sql,我想获得一些属性、交易、学生等的详细信息,我在ProgressCard表中使用linq记录了他们的id。 并将结果数据保存为XMl 我正在这样做 public List<ShowProgressCard> GetCardListToShow() { try { List<ShowProgressCard> CardList = new List<ShowProgressCard>();

我想获得一些属性、交易、学生等的详细信息,我在ProgressCard表中使用linq记录了他们的id。 并将结果数据保存为XMl

我正在这样做

    public List<ShowProgressCard> GetCardListToShow()
    {
        try
        {
            List<ShowProgressCard> CardList = new List<ShowProgressCard>();
            using (ProgressCardLINQDataContext c = new ProgressCardLINQDataContext())
            {
                CardList = (from card in c.GetTable<T_PROGRESSCARD>()
                            where card.RecordStatus.Equals(RecordStatus.Active)
                            select new ShowProgressCard
                            {
                                Session=(from session in c.T_SESSIONs
                                         where session.Id.Equals(card.SessionId)
                                         select session.Name).ToString(),
                                Trade=(from trade in c.T_TRADEs
                                       where trade.Id.Equals(card.TradeId)
                                       select trade.Name).ToString(),
                                Student=(from student in c.T_STUDENTs
                                         where student.Id.Equals(card.StudentId)
                                         select student.Name).ToString(),
                                Test=(from test in c.T_TESTs
                                      where test.Id.Equals(card.TestId)
                                      select test.Name).ToString(),
                                MaxMarks = (from test in c.T_TESTs
                                            where test.Id.Equals(card.TestId)
                                            select test.MaxMarks).ToString(),
                                MarksObtain=card.MarksObtain.ToString(),
                                Percentage=card.Percentage.ToString("N2")
                            }).ToList<ShowProgressCard>();
            }
            return CardList;
        }
        catch
        {
            return new List<ShowProgressCard>();
        }
    }
但是给了我意想不到的价值

<ShowProgressCard>
<Session>System.Collections.Generic.List`1[System.String]</Session>
<Trade>System.Collections.Generic.List`1[System.String]</Trade>
<Student>System.Collections.Generic.List`1[System.String]</Student>
<Test>System.Collections.Generic.List`1[System.String]</Test>
<MaxMarks>System.Collections.Generic.List`1[System.Int32]</MaxMarks>
<MarksObtain>123</MarksObtain>
<Percentage>0.000000000000000e+000</Percentage>
</ShowProgressCard>
请帮我追踪错误

                            Session=(from session in c.T_SESSIONs
                                     where session.Id.Equals(card.SessionId)
                                     select session.Name).ToString(),
                            Trade=(from trade in c.T_TRADEs
                                   where trade.Id.Equals(card.TradeId)
                                   select trade.Name).ToString(),
                            Student=(from student in c.T_STUDENTs
                                     where student.Id.Equals(card.StudentId)
                                     select student.Name).ToString(),
                            Test=(from test in c.T_TESTs
                                  where test.Id.Equals(card.TestId)
                                  select test.Name).ToString(),
                            MaxMarks = (from test in c.T_TESTs
                                        where test.Id.Equals(card.TestId)
                                        select test.MaxMarks).ToString(),
此块只返回值的IEnumerables。在ToString之前添加Single或First:

MaxMarks = (from test in c.T_TESTs where test.Id.Equals(card.TestId) select test.MaxMarks).Single().ToString(),

请你再帮我一个忙,我想取小数点后两位的百分比。我试着在ToString方法中使用N2,但它不起作用。你知道为什么吗?MSDN知道C字符串格式,但我从内存中不知道。