Warum kann ich nicht mit einem Wörterbuch mit Entity Framework

Dictionary<int, string> D = new Dictionary<int, string>();
D.Add(0, "Insert");
D.Add(1, "Update");
D.Add(2, "Delete"); 

using (SerasMacEntity SME = new SerasMacEntity())
{
    var SQL = (from p in SME.tbl_admin_islem
               let testx = D.Where(x => x.Key == p.islem).Select(x => x.Value).FirstOrDefault()
               orderby p.tarih descending
               select new
               {
                  p.id,
                  p.islem,
                  p.tarih
               });

    Store1.DataSource = SQL;
    Store1.DataBind();
}

Seine Angabe dieser Fehler;

'- System.Sammlungen.Generisches.KeyValuePair`2' und Nur primitive Typen
('wie Int32, String und Guid')

Ich verwenden Sie diese Methode, Linq, aber ich kann nicht mit Entitäten.

public class table
{
    public int ID { get; set; }
    public string Adi { get; set; }
    public int IslemID { get; set; }
    public table() { }
    public table(int _ID, string _Adi, int _IslemID)
    {
        _ID = ID;
        _Adi = Adi;
        _IslemID = IslemID;
    }
}

public List<table> table_list = new List<table>(new table[]
{
    new table{ID=1,Adi="A1",IslemID=0},
    new table{ID=2,Adi="A2",IslemID=1},
    new table{ID=3,Adi="A3",IslemID=2},
    new table{ID=4,Adi="A4",IslemID=1},
    new table{ID=5,Adi="A5",IslemID=0},
    new table{ID=6,Adi="A6",IslemID=2},
    new table{ID=7,Adi="A7",IslemID=0},
    new table{ID=8,Adi="A8",IslemID=1},
    new table{ID=9,Adi="A9",IslemID=3}
});

public Dictionary<int, string> option_dictionary = new Dictionary<int,string>()
{
    {0, "OK"},
    {1, "NO"},
    {2, "YA"},
    {3, "OH"}
};

public void TestL()
{
    string b = option_dictionary.Where(x => x.Key == 1).Select(x =>x.Value).First();

    var SQL = (from p in table_list
    let test = option_dictionary.Where(x => x.Key == p.IslemID).Select(x => x.Value).First()
    select new
    {
        p.ID,
        p.Adi,
        test
    }
    );
}

Diese Methode funktioniert in Linq. Seine nicht funktioniert in Person.

Vielen Dank für Ihre Hilfe.

InformationsquelleAutor Ahmet YETİK | 2012-01-07
Schreibe einen Kommentar