Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MaxenceMouchard opened this issue Jan 9, 2024 · 0 comments

Comments

@MaxenceMouchard
Copy link

MaxenceMouchard commented Jan 9, 2024

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();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant