NHibernate 3CR1: conversion to Sql, generates sql syntax problem from unnecessary brackets

My database schema is described below:

Form ↔ Magazine

<--- → Seller1

<--- → Seller2

<--- → Seller3

I have a basic entity (form), a one-to-one relationship with another object (a magazine) and a one-to-many relationship for children (sellers).

I want to pull out all the forms that one of their Sellers satisfies certain conditions.

Unfortunately, I am having some problems:

If I run the following procedure:

[Test] public void Can_Get_Forms_Where_CorporationNumber_Is_510778087_Metohd0() { var CorporationNumber = "513514950"; var list0 = formRepository .Where(x => x.Sellers.Any(y => y.CorporationNumber == CorporationNumber)) .Fetch(x=> x.Sellers) .Fetch(x => x.Log) .Take(10).ToList(); CollectionAssert.IsNotEmpty(list0); } 

Then I will get sql syntax error

 Incorrect syntax near ',' 

Using NHProf, I took a query and found a problem. I reduced my query to a Count query to focus on the problem:

 select TOP ( 10 /* @p0 */) cast( count( *) as INT) as col_0_0_ from BillOfSaleForm form0_ where exists ( select ( sellers1_.FormID, sellers1_.tdNum) from BillOfSaleSeller sellers1_ where form0_.FormID=sellers1_.FormID and ( ( sellers1_.MisparTagid is null) and ( '513514950' /* @p1 */ is null) or sellers1_.MisparTagid='513514950' /* @p1 */) ) 

Note that the section

  select ( sellers1_.FormID, sellers1_.tdNum) 

Has extra brackets !

Of course, if we delete the executed parentheses request.

+1
source share

All Articles