简体   繁体   English

无法执行Nhibernate查询

[英]Cannot execute Nhibernate query

I get the following Nhiberante error, but have no idea why: 我收到以下Nhiberante错误,但不知道为什么:

could not execute query [ select attachment0_.AttachmentId as Attachme1_9_, attachment0_.Name as Name9_, attachment0_.IconUrl as IconUrl9_, attachment0_.UserId as UserId9_, attachment0_.AttachmentTypeId as Attachme6_9_, attachment0_.IsDeleted as IsDeleted9_, attachment0_.ArrivalTime as ArrivalT8_9_, attachment0_.LocationId as LocationId9_ from Attachment_Attachment attachment0_ where attachment0_.DYNAMIC_TYPE='Attachment' and 1=0 ] [SQL: select attachment0_.AttachmentId as Attachme1_9_, attachment0_.Name as Name9_, attachment0_.IconUrl as IconUrl9_, attachment0_.UserId as UserId9_, attachment0_.AttachmentTypeId as Attachme6_9_, attachment0_.IsDeleted as IsDeleted9_, attachment0_.ArrivalTime as ArrivalT8_9_, attachment0_.LocationId as LocationId9_ from Attachment_Attachment attachment0_ where attachment0_.DYNAMIC_TYPE='Attachment' and 1=0] 无法执行查询[选择附件0_.AttachmentId作为Attachme1_9_,附件0_.Name作为Name9_,附件0_.IconUrl作为IconUrl9_,附件0_.UserId作为UserId9_,附件0_.AttachmentTypeId作为Attachme6_9_,附件0_.IsDeleted作为IsDeleted9_T,附件0_。 LocationId作为Attachment_Attachment附件0_中的LocationId9_,其中annex0_.DYNAMIC_TYPE ='Attachment'并且1 = 0] [SQL:选择附件0_.AttachmentId作为Attachme1_9_,附件0_.Name作为Name9_,附件0_.IconUrl作为IconUrl9_,附件0_.UserchType作为UserId9_,作为Attachme6_9_,附件0_.IsDeleted作为IsDeleted9_,附件0_.ArrivalTime作为ArrivalT8_9_,附件0_.LocationId作为来自Attachment_Attachment附件0_的LocationId9_,其中附件0_.DYNAMIC_TYPE ='附件',并且1 = 0]

Update: 更新:

inner exception: 内部异常:

Failed to convert parameter value from a WhereSelectListIterator`2 to a Guid.

My query: 我的查询:

x => locationsIds.Contains(x.LocationId)

locationsIds is probably an IEnumerable returned by a call to Where . locationsIds可能是通过调用Where返回的IEnumerable。 The simplest solution is to explicitly convert it to a list: 最简单的解决方案是将其显式转换为列表:

var idsList = locationIds.ToList();
x => idsList.Contains(x.LocationId);

Check the InnerException . 检查InnerException I'm sure it will point you to the correct place. 我敢肯定,它将指向您正确的地方。

I know this specific question have been answered here, but I have also had this exception (with different column names) and the reason it failed was that I had used the wrong database. 我知道这里已经回答了这个特定问题,但是我也遇到了此异常(具有不同的列名),并且失败的原因是我使用了错误的数据库。 I had added a new table to one database, but when I ran the code I had configured it to use another database. 我已经向一个数据库中添加了一个新表,但是在运行代码时,我已将其配置为使用另一个数据库。 Once I used the correct database the error disappeared. 一旦我使用了正确的数据库,错误就消失了。

I hope this helps someone! 我希望这可以帮助别人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM