2016-06-16 4 views
-1

qresultを追加しようとしたときにエラーが発生しました。誰でも私のコードを修正/修正する方法をアドバイス/ガイドできますか?おかげ はSystem.Collections.Generic.List <>から>は、System.Collections.Generic.List <>からSystem.Collections.Generic.IEnumerable <>に変換できません。

public class SystemAccessList 
{ 
    public SystemAccess SystemAccess { get; set; } 

    public List<SystemAccess> SystemAccessList { get; set; } 

    SystemDbContext db; 

public void setDbContext(PALMSConfigDbContext _db) 
    { 
     db = _db; 
    } 

    public SystemAccessList GetAccessList(SystemAccessList systemAccessList) 
    { 

    var qresult = db.tbl_SystemAccessList 
      .GroupBy(g => g.ClassID) 
      .AsEnumerable().Select(c => 
      { 
       var rr = new ResultRow { Class = c.Key }; 
       foreach (var r in db.tbl_SystemAccessList.GroupBy(gg => gg.StudentID)) 
       { 
        rr.Student[r.Key] = "N"; 
       } 
       foreach (var r in c.Where(w => w.ClassID == c.Key)) 
       { 
        rr.Student[r.StudentID] = "Y"; 
       } 
       return rr; 
      }).ToList(); 

    systemAccessList.SystemAccessList.AddRange(qresult); 
    return systemAccessList; 
} 

class ResultRow 
{ 
    public ResultRow() 
    { 
     Student = new Dictionary<string, string>(); 
    } 

    public string Class { get; set; } 

    public IDictionary<string, string> Student { get; set; } 

    public string GetHeader() 
    { 
     return Student.Aggregate("Class", (current, s) => current + "|" + s.Key); 
    } 

    public string GetSolidRow() 
    { 
     return Student.Aggregate(Class, (current, s) => current + "|" + s.Value); 
    } 
    } 

    public class SystemAccess 
    { 
     [Key] 
     public int ID { get; set; } 
     public string ClassID { get; set; } 
     public string StudentID { get; set; } 
    } 
+3

SystemAccessListはどのようなタイプですか? – matt

+0

qresultがSystemAccessList以外の新しいリストを返した可能性があります。qresultの型をSystemAccessListに変換してその範囲内に結果を追加するには、明示的なキャストが必要です。 –

+0

公開リスト<> ....私はそれを変換する方法を知っているかもしれませんか? – WolfPack

答えて

0

System.Collections.Generic.IEnumerable <に変換することはできませんあなたのqresultSelectのあなたがそこに持っているので、タイプList<ResultRow>のものであろう。ターンResultRowの基本クラス、またはインタフェースResultRow器具のいずれかである任意XxxためIEnumerable<Xxx>ある(私はResultRowが参照型(class)であると仮定した場合)List<ResultRow>IEnumerable<ResultRow>れています。

お客様のSystemAccessListList<SystemAccess>であり、AddRangeの方法はIEnumerable<SystemAccess>が必要です。

ResultRow a SystemAccess(継承によって)の場合、すべてが問題ありません。そうではありません。コンパイル時にList<ResultRow>IEnumerable<SystemAccess>ではないというメッセージが表示されるはずです。

+0

はい、IEnumerable <>に変換中にエラーが発生しました。私はそれを固定する方法を知ってもいいですか? – WolfPack

関連する問題