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

Request: Support the Immutable Entities #465

Closed
mikependon opened this issue Jul 6, 2020 · 6 comments
Closed

Request: Support the Immutable Entities #465

mikependon opened this issue Jul 6, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request fixed The bug, issue, incident has been fixed. request A request from the community. todo Things to be done in the future

Comments

@mikependon
Copy link
Owner

mikependon commented Jul 6, 2020

Currently, RepoDb does not support an immutable classes when fetching the data from the database. This is true to all fetch operations like Query, QueryAll, BatchQuery and/or even in the ExecuteQuery method.

See the sample code snippets below:

public class Customer
{
     public Customer(int id, string name, ...)
     {
          Id = id;
          Name = name;
          ...
     }

     public int Id { get; set; }

     public string Name { get; set; }
}

Note: In F#, by default, the classes are immutable and that the developers need to explicitly specify the CLIMutableAttribute to make it work.

More information will soon to be placed here.

@mikependon mikependon added enhancement New feature or request todo Things to be done in the future request A request from the community. labels Jul 6, 2020
@mikependon mikependon self-assigned this Jul 6, 2020
@mikependon mikependon changed the title Request: Support Immutable Entities Request: Support the Immutable Entities Jul 6, 2020
@GeeWee
Copy link
Contributor

GeeWee commented Jul 6, 2020

If you want to get some inspiration, I think this is the PR where it was it was implemented in System.Text.Json. I linked to the file which seems like a good starting point for the implementation, as the PR is rather noisy.

@isaacabraham
Copy link

@mikependon FYI - this also seems to be required on Insert operations as well.

@mikependon
Copy link
Owner Author

@isaacabraham , for as long as you are passing the models, the compiler reflects all the properties that are readable. I would assume that immutable classes should be working by default. However, RepoDb insert operation is automatically setting back the PK/Identity value to the model after the operation, it seems to fail it there. In anyway, the PK/Identity value is also returned by the method itself, you can process afterwards.

Btw, which case do you think it will fail?

@isaacabraham
Copy link

It fails on the Insert call with a null reference exception - I suspect trying to find the setter on the properties which do not exist.

@mikependon
Copy link
Owner Author

@isaacabraham - this is noted. FYI, this user story has been pinned and is next in line, will be a part of the next version beta release, together with the other F# related request #499. I will look at this and make sure it is covered by the Integration Tests before the beta release.

@mikependon
Copy link
Owner Author

This has been fixed and is now available at RepoDb v1.12.3. Closing this incident ticket now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed The bug, issue, incident has been fixed. request A request from the community. todo Things to be done in the future
Projects
None yet
Development

No branches or pull requests

3 participants