回答編集履歴

3

追記

2019/02/08 18:53

投稿

退会済みユーザー
test CHANGED
@@ -211,3 +211,7 @@
211
211
 
212
212
 
213
213
  なので、SQLite3 で DataTime 型を使えるならそれを使うのが正解のようです。
214
+
215
+
216
+
217
+ ただし、DB に NULL があると、SQL に変換されるということなので、期待通りの結果にならないかもしれません。

2

追記

2019/02/08 18:53

投稿

退会済みユーザー
test CHANGED
@@ -193,3 +193,21 @@
193
193
  }
194
194
 
195
195
  ```
196
+
197
+
198
+
199
+ **【追記2】**
200
+
201
+
202
+
203
+ x_x さんが言われる通り、Linq to Object では問題ないが Linq to Entities では SQL に変換できないのでダメということだったようです。
204
+
205
+
206
+
207
+ LINQにも色々 ~SQLに変換されるモノと変換されないモノ
208
+
209
+ [https://codezine.jp/article/detail/8474](https://codezine.jp/article/detail/8474)
210
+
211
+
212
+
213
+ なので、SQLite3 で DataTime 型を使えるならそれを使うのが正解のようです。

1

追記

2019/02/08 15:06

投稿

退会済みユーザー
test CHANGED
@@ -45,3 +45,151 @@
45
45
 
46
46
 
47
47
  試してないのでハズレだったらすみません。
48
+
49
+
50
+
51
+ **【追記】**
52
+
53
+
54
+
55
+ 下の 2019/02/08 23:11 の私のコメントで「ご参考に、試したコードを回答欄にアップしておきます」と書きましたが、それを以下に書いておきます。
56
+
57
+
58
+
59
+ ```
60
+
61
+ using System;
62
+
63
+ using System.Collections.Generic;
64
+
65
+ using System.Linq;
66
+
67
+ using System.Text;
68
+
69
+ using System.Threading.Tasks;
70
+
71
+ using System.Data;
72
+
73
+ using System.Configuration;
74
+
75
+
76
+
77
+ namespace ConsoleApplication1
78
+
79
+ {
80
+
81
+ public class Customers
82
+
83
+ {
84
+
85
+ public int Id { get; set; }
86
+
87
+ public string Date { get; set; }
88
+
89
+ }
90
+
91
+
92
+
93
+ public class Filter
94
+
95
+ {
96
+
97
+ public int Id { get; set; }
98
+
99
+ public DateTime Date { get; set; }
100
+
101
+ }
102
+
103
+
104
+
105
+ class Program
106
+
107
+ {
108
+
109
+ static void Main(string[] args)
110
+
111
+ {
112
+
113
+ IEnumerable<Customers> customers = new List<Customers>
114
+
115
+ {
116
+
117
+ new Customers { Id = 1, Date = "2019/1/1" },
118
+
119
+ new Customers { Id = 2, Date = "2019/1/2" },
120
+
121
+ new Customers { Id = 3, Date = "2019/1/3" }
122
+
123
+ };
124
+
125
+
126
+
127
+ var list = (from c in customers
128
+
129
+ select new Filter
130
+
131
+ {
132
+
133
+ Id = c.Id,
134
+
135
+ Date = DateTime.Parse(c.Date)
136
+
137
+ }).AsQueryable();
138
+
139
+
140
+
141
+ foreach(Filter f in list)
142
+
143
+ {
144
+
145
+ Console.WriteLine($"Id: {f.Id}, Date: {f.Date}");
146
+
147
+ }
148
+
149
+
150
+
151
+ // 結果は:
152
+
153
+ // Id: 1, Date: 2019/01/01 0:00:00
154
+
155
+ // Id: 2, Date: 2019/01/02 0:00:00
156
+
157
+ // Id: 3, Date: 2019/01/03 0:00:00
158
+
159
+
160
+
161
+ var list2 = (from c in customers
162
+
163
+ select c).AsQueryable();
164
+
165
+
166
+
167
+ var filter = new Filter { Id = 1, Date = new DateTime(2019, 1, 2) };
168
+
169
+ list2 = list2.Where(x => DateTime.Parse(x.Date) >= filter.Date);
170
+
171
+
172
+
173
+ foreach (Customers c in list2)
174
+
175
+ {
176
+
177
+ Console.WriteLine($"Id: {c.Id}, Date: {c.Date}");
178
+
179
+ }
180
+
181
+
182
+
183
+ // 結果は:
184
+
185
+ // Id: 2, Date: 2019/1/2
186
+
187
+ // Id: 3, Date: 2019/1/3
188
+
189
+ }
190
+
191
+ }
192
+
193
+ }
194
+
195
+ ```