1: // LINQ To SQL
2:
3: static IEnumerable<Item> GetItems<T>(
4: Func<T, string> keyFunc,
5: Func<T, string> textFunc,
6: Func<T, bool> whereSelector,
7: Func<T, object> sortFunc)
8: where T : class
9: {
10: using (ClassesDataContext dc = new ClassesDataContext())
11: {
12: return (from entity in dc
13: .GetTable<T>()
14: .Where(whereSelector)
15: .OrderBy(sortFunc)
16: select new Item
17: {
18: Key = keyFunc.Invoke(entity),
19: Value = textFunc.Invoke(entity)
20: }).ToArray();
21: }
22: }
23:
24: // LINQ TO Entities
25:
26: static IEnumerable<Item> GetItems<T>(
27: Func<T, string> keyFunc,
28: Func<T, string> textFunc,
29: Func<T, bool> whereSelector,
30: Func<T, object> sortFunc)
31: where T : EntityObject
32: {
33: using (Entities entities = new Entities())
34: {
35: return (from entity in entities
36: .CreateQuery<T>("[" + typeof(T).Name + "]")
37: .Where(whereSelector)
38: .OrderBy(sortFunc)
39: select new Item
40: {
41: Key = keyFunc.Invoke(entity),
42: Value = textFunc.Invoke(entity)
43: }).ToArray();
44: }
45: }