Skip to content

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

Open
@MaxenceMouchard

Description

@MaxenceMouchard

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_3_0'
[SQL: select organizati2_.Id as col_0_0_, organizati2_.Name as col_1_0_, user0_.Id as col_2_0_, . as col_3_0_, organizati4_.Id as id1_0_, organizati4_.Name as name2_0_ 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();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions