简体   繁体   中英

Cannot execute Nhibernate query

I get the following Nhiberante error, but have no idea why:

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]

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 . The simplest solution is to explicitly convert it to a list:

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

Check the 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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