nhibernate / fluent-nhibernate

Fluent NHibernate!
BSD 3-Clause "New" or "Revised" License
1.66k stars 686 forks source link

GenericADOException - Error in sql request generation when null checking a hasmany reference of an abstract class #632

Open MaxenceMouchard opened 9 months ago

MaxenceMouchard commented 9 months ago

Hi, When I check the nullity on a list in a select clause, I have a problem generating the sql query where there is ' . as col_30' `[SQL: select organizati2.Id as col_00, organizati2_.Name as col_10, user0_.Id as col_20, . as col_30, organizati4_.Id as id10, organizati4_.Name as name20 from Users user0 left outer join OrganizationToUser organizati1 on user0.Id=organizati1.UserId left outer join Organizations organizati2 on organizati1.OrganizationId=organizati2.Id inner join OrganizationToUser organizati3 on user0.Id=organizati3.UserId inner join Organizations organizati4 on organizati3.OrganizationId=organizati4_.Id] ---> System.Data.SqlClient.SqlException (0x80131904): Syntaxe incorrecte vers le mot clé 'as'.`

when I remove the null check, there is no more problem. Also, there is no problem if I remove my abstract class and implement the property in the base class.

I think there's a problem on your side, or have I missed a fundamental principle?

Query: session.Query<User>().Select(x => new { fullName = (x.OrganizationList != null ? x.OrganizationList.Select(y => y.Name) : null )).ToList()

Classes:

public abstract class AbstractUser
{
    public AbstractUser()
    {
        OrganizationList = new HashSet<Organization>();
    }

    public virtual ISet<Organization> OrganizationList { get; set; }
}

public class User : AbstractUser
{
    public virtual Guid Id { get; set; }
}

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("Users");

        Id(x => x.Id);
        HasManyToMany(x => x.OrganizationList)
            .Table("OrganizationToUser") // Nom de la table de liaison
            .ParentKeyColumn("UserId")   // Clé étrangère de User dans la table de liaison
            .ChildKeyColumn("OrganizationId") // Clé étrangère de Organization dans la table de liaison
            .Inverse()
            .Cascade.All();
    }
}