And*_*nos 3 linq vb.net linq-to-entities
我有以下LINQ to实体查询(使用odp.net):
Dim query = from Elemento in X.VIEW where Elemento.code = "10" Select New With {Elemento.code, .Time = Elemento.Time.ToString("HH:mm")} query.ToList()
代码会抛出该ToList()
方法的异常:
LINQ to Entities does not recognize the method 'System.String ToString()'
我已经阅读了所有关于此的内容,但还没有找到一个简单的解决方法.
Lazyberezovsky有正确的答案,我之前无法让它工作,因为我这样做:
Dim query = (from Elemento in X.VIEW where Elemento.code = "10" Select New With {Elemento.code, Elemento.Time}).ToList Dim query2 = from elemento in query Select New With {elemento.code, TIME = elemento.Time.ToString("HH:mm")} Dim result = query2.ToList()
但这不起作用,显然你必须一步到位.
您可以将DateTime转换为字符串内存.只需ToList
在转换时间之前拨打电话:
在C#中:
var query = from Elemento in X.VIEW
where Elemento.code == "10"
select new { Elemento.code, Elemento.Time };
var result = query.ToList() // now you are in-memory
.Select(x => new { x.code, Time = x.Time.ToString("HH:mm") });
Run Code Online (Sandbox Code Playgroud)
在VB.Net中:
Dim query = From Elemento In X.VIEW
Where Elemento.code = "10"
Select New With {Elemento.code, Elemento.Time}
Dim result = query.ToList() _
.Select(Function(x) New With {x.code, .Time = x.Time.ToString("HH:mm")})
Run Code Online (Sandbox Code Playgroud)
BTW为什么要选择Elemento.code
结果,如果你在哪里运算符过滤它(它总是等于"10").
归档时间: |
|
查看次数: |
1840 次 |
最近记录: |