-
Notifications
You must be signed in to change notification settings - Fork 127
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
[BUG] Query failed when field mapping used on FSharp records. #662
Comments
This is a good finding actually. In C#, the type that was created in F# is automatically converted into Anonymous Type, that is immutable. RepoDB on the other hand only supports the mapping in both the Class and Property level, not on the ctor arguments. I would assume that the issue is on the alignment of the ctor argument, that is why push operations (i.e: Insert, etc) is working. Can you try putting Also, when do you need the fix for this? Thank you for this report. |
@mikependon Thanks for the quick response. Adding I've created a tiny F# example generated into C#. In case of the link above doesn't work (click to expand)
go to https://sharplab.io/ and replace F# code with code below open System
type MapAttribute(name: string) =
inherit Attribute()
//[<CLIMutable>]
type User = {
Id: int
[<Map("first_name")>]
Name: string
} As you can see, the result will be C# class with a constructor and 2 read-only properties. The ....
public User(int id, string name)
{
Id@ = id;
Name@ = name;
}
[CompilationMapping(SourceConstructFlags.Field, 0)]
public int Id
{
get
{
return Id@;
}
}
[Map("first_name")]
[CompilationMapping(SourceConstructFlags.Field, 1)]
public string Name
{
get
{
return Name@;
}
}
.... So, it looks OK. As of timing, I'm not in hurry :) |
Oh, I did the same thing, never expect that it will generate 2 ctors at all if it is converted to C# (new knowledge). public User(int id, string name)
{
Id@ = id;
Name@ = name;
}
public User()
{
} Yes, that is what I am saying, the type This could as well complicate the things since the converted object in C# has placed the If you are a C# developer, how would you prefer it to do? Would you place it on the ctor argument (like below)? On this case, public class User
{
public User(int id, [Map("first_name")] string name)
{
Id = id;
Name = name;
}
public int Id { get; set; }
public string Name { get; set; }
} Or, would you rather just put in on the property. public class User
{
public User(int id, string name)
{
Id = id;
Name = name;
}
public int Id { get; set; }
[Map("first_name")]
public string Name { get; set; }
} If you cannot provide an input, please feel free to ask an opinion from the other C# users, so this would remove my bias. I recommend the first approach though. |
@mikependon How does it work currently when a property tagged with I would vote for the second one, but I'm not into the actual implementation and it is hard for me to predict the impact. What is the next step do you see? How I can help you with progress here? |
For the immutable types, the ctor argument public class User
{
public User(int id, string name)
{
Id = id;
CompleteName = name;
}
public int Id { get; set; }
public string CompleteName { get; set; }
} If your class is mutable, then it works as expected as you mentioned. The problem to your case is that, the The option #2 is also good, all that I have to do is to implement the ctor argument and property projection. The problem to this is, if they are not equal on the name, then the same exception will throw. |
@DmitryBatalov - but since the F# is always generating the equal ctor argument and property (both name and type), then it is safe to assume the option 2. The option 1 is an additional level of mapping in which I think would add further big changes to the library for such a small case. I decided to also go for option 2 (as of writing this). |
Thanks for the quick fix. 🥇 |
This is now available on version RepoDb v1.12.5-beta5. |
The model in the code doesn't match the database. I use the mapping feature in the following way:
and then try to read data from database
As a result, I've got the exception:
When the model match DB, then I can read without any issues.
Also, insert operation work with mapping without any issue.
Environment: ubuntu 20.04, .net core 3.1
Version: RepoDb.MySql 1.1.2
Database: MySql 8.0
Example: consoleapp.zip
The text was updated successfully, but these errors were encountered: