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();
}
Это дает эту ошибку;
'System.Collections.Generic.KeyValuePair`2' и только примитивные типы
(«такие как Int32, String и Guid»)
Я использую этот метод в Linq, но не могу использовать Entity.
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
}
);
}
Этот метод работает в Linq. В Entity не работает.
Спасибо за вашу помощь.