我有一个返回LINQ语句结果的函数。请检查发生错误的代码段。
import psutil
for proc in psutil.process_iter(attrs=['pid', 'name']):
if 'ichat' in proc.info['name']:
proc.kill()
我从 var result = devices
.Select(d =>
new
{
deviceName = d.SystemDeviceName,
deviceType = d.SystemDeviceTypeName,
dvrVersion = d.DVRVersion,
numCameras = d.NumCameras,
lastPing = d.LastPingDate!=null? d.LastPingDate:null,
audioType = d.AudioTypeName ?? "(None)",
videoProvider = d.Provider,
ipAddress = d.IPAddress,
vpnIpAddress = d.VPNIPAddress,
internalUseIpAddress = d.InternalUseIPAddress,
viewLiveLink = "<a onclick='openViewer(" + d.SystemDeviceID + ", true)'>"
+ (ShowIcon ? "<img src='images/video-live.png'>" : String.Empty)
+ (ShowIcon && ShowText ? " " : String.Empty)
+ (ShowText ? "View Live" : String.Empty)
+ "</a>",
viewSearchLink = "<a onclick='openViewer(" + d.SystemDeviceID + ", false)'>"
+ (ShowIcon ? "<img src='images/video-recorded.png'>" : String.Empty)
+ (ShowIcon && ShowText ? " " : String.Empty)
+ (ShowText ? "View Recorded" : String.Empty)
+ "</a>",
})
.ToArray();
response.Object = result;
return response;
声明中收到错误。
错误是:
无法将类型'System.Int32'强制转换为'System.Object'。 LINQ to Entities仅支持转换EDM原语或枚举类型。
我试图确定哪个分配引发了错误。以下行导致错误
var result = devices.select
设备的类别防御是,
viewLiveLink = "<a onclick='openViewer(" + d.SystemDeviceID + ", true)'>"
+ (ShowIcon ? "<img src='images/video-live.png'>" : String.Empty)
+ (ShowIcon && ShowText ? " " : String.Empty)
+ (ShowText ? "View Live" : String.Empty)
+ "</a>",
viewSearchLink = "<a onclick='openViewer(" + d.SystemDeviceID + ", false)'>"
+ (ShowIcon ? "<img src='images/video-recorded.png'>" : String.Empty)
+ (ShowIcon && ShowText ? " " : String.Empty)
+ (ShowText ? "View Recorded" : String.Empty)
+ "</a>",
请帮我清除错误。提前谢谢。
答案 0 :(得分:1)
实体框架无法将所有linq查询转换为sql,但您可以预先查询。
var result = devices
.ToArray()//<< solution
.Select(d => new{
..
})
.ToArray();
我希望这有帮助。
答案 1 :(得分:0)
在将此值作为字符串
的一部分之前,请尝试将SystemDeviceID
转换为字符串
viewLiveLink = "<a onclick='openViewer(" + d.SystemDeviceID.ToString() + ", true)'>"
+ (ShowIcon ? "<img src='images/video-live.png'>" : String.Empty)
+ (ShowIcon && ShowText ? " " : String.Empty)
+ (ShowText ? "View Live" : String.Empty)
+ "</a>",
viewSearchLink = "<a onclick='openViewer(" + d.SystemDeviceID.ToString() + ", false)'>"
+ (ShowIcon ? "<img src='images/video-recorded.png'>" : String.Empty)
+ (ShowIcon && ShowText ? " " : String.Empty)
+ (ShowText ? "View Recorded" : String.Empty)
+ "</a>",
答案 2 :(得分:0)
首先,您使用的是EF6还是EF Core?
其次,我们几乎没有关于devices
是什么或可能是什么的信息,如果你能设法提供更多信息,那就太棒了。
第三,尝试隔离错误的指令,使其不会被不必要/不相关的代码片段臃肿,你的帖子可能会被重构以包含与你的问题相关的核心信息,你也可以解决它'橡胶迷人这样做的风格。