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

Inconsistent object mapping behavior when querying using LINQ vs QueryToListAsync #4437

Open
jeffijoe opened this issue Feb 28, 2024 · 2 comments

Comments

@jeffijoe
Copy link

Describe your issue

When using QueryToListAsync<Test> where Test is a record with a primary constructor and [property: Column("some_column")] attributes, it appears the column names specified in the attributes are not being used. If the record does not have a constructor, then it works fine. Additionally, using connection.GetTable<MyType>() to query, then the record with a primary constructor also works. Removing the constructor makes it work with QueryToListAsync.

Steps to reproduce

Using the following as our table/query result type

[Table("test")]
public record Test(
    [property: Column("some_column")]
    string SomeColumn);

When using the following:

await connection.QueryToListAsync<Test>("select some_column from test")

The resulting records will have null in SomeColumn because the [Column] attribute which provides the correct name is not being used.

If instead I do

await db.GetTable<Test>().FirstOrDefaultAsync();

Then the column mapping works and I get the expected value in SomeColumn.

If I change my record to not have a constructor, then everything works fine with QueryToListAsync as well:

[Table("test")]
public record Test
{
    [Column("some_column")]
    public string SomeColumn { get; init; }
}

Is there a difference in how Linq2Db handles object mapping for LINQ-based queries vs SQL-based ones?

Environment details

Linq To DB version: 5.4

Database (with version): Postgres 13

ADO.NET Provider (with version): Npgsql 8.0

Operating system: macOS

.NET Version: 8.0

@MaceWindu
Copy link
Contributor

Yes, currently mapping for raw queries works in a different way. We will unify it in upcoming 6.0 release

@jeffijoe
Copy link
Author

Thank you @MaceWindu, and thank you for all the work you guys are doing on Linq2Db, it's an incredible library! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants