2012-03-29 6 views
1

私は次のコードだ:私はDictionary<int?, ScanClass>LINQの辞書値にオブジェクトを追加しますか?

ScanClassでDitionaryを変更したい

private Dictionary<int?, byte[]> GetAllLocalScanFiles() 
{ 
    using (DZine_IStylingEntities ctxLocal = new DZine_IStylingEntities()) 
    { 
     _scanDictionaryLocal = ctxLocal.tblScan 
       .Select(s => new { s.MEMBERID, s.scanFileAvatar }) 
       .AsParallel() 
       .ToDictionary(s => s.MEMBERID, s => s.scanFileAvatar); 
    } 
    return _scanDictionaryLocal; 
} 

は辞書の値のオブジェクトを与えるために、オブジェクト

public class ScanClass 
{ 
    public byte[] ScanFileAvatar { get; set; } 
    public byte[] Hair { get; set; } 
} 

ことが可能です? PS私はルックアップでこれをしたくありません。

ありがとうございます!あなたがあなたの元のエンティティでhair性質を持っていると仮定しています

private Dictionary<int?, ScanClass> GetAllLocalScanFiles() 
{ 
    using (DZine_IStylingEntities ctxLocal = new DZine_IStylingEntities()) 
    { 
     return ctxLocal.tblScan 
       .Select(s => new { s.MEMBERID, s.scanFileAvatar, s.hair }) 
       .AsParallel() 
       .ToDictionary(s => s.MEMBERID, s => new ScanClass { 
            hair = s.hair, 
            scanFileAvatar = s.scanFileAvatar 
           }); 
    } 
} 

答えて

4

あなたは、おそらくのような何かをしたいような音。

AsParallelが本当にあなたをここに助けようとしていることは明らかではありません。 理由がである場合を除いて、AsEnumerable()を代わりに使用することを検討してください。

+0

Jon quick question hairとscanFileAvatarは20MB +の2つの大きなデータ小道具です、そして、私がこのクエリを実行すると、私はこれを避けるか、または修正しますか? – dg90

+0

@ daageu:おそらく、データベース全体を一度に取り込もうとしないでください...もっと良い答えを出すために何をしようとしているのかについての十分な情報はありません。 –

1
_scanDictionaryLocal = ctxLocal.tblScan 
    .ToDictionary(s => s.MEMBERID, s => new ScanClass() 
    { 
     ScanFileAvatar = s.scanFileAvatar, 
     Hair = s.hair 
    }); 
+0

私はちょうど '選択'と 'AsParallel'をスキップし、直接' ToDictionary'を行います – Magnus

関連する問題