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

[MERGE] Immutable data models are not supported #4237

Open
dtila opened this issue Jul 31, 2023 · 5 comments
Open

[MERGE] Immutable data models are not supported #4237

dtila opened this issue Jul 31, 2023 · 5 comments

Comments

@dtila
Copy link

dtila commented Jul 31, 2023

Hi guys, I see some limitations in the library with mapped domains that are immutable.

I will take an example from documentation the MergeAPI:

db.Table
    .Merge()
    .Using(source)
    .OnTargetKey()
    .InsertWhenNotMatched(source => new TargetRecord()
    {
        Field1 = 10,
        Field2 = source.Field2,
        Field3 = source.Field1 + source.Field2
    })
    .Merge();

If I TargetRecord is immutable, then specifying properties does not work.

However with EF Core working with immutable objects work. An example are the new functions ExecuteUpdate from EF7
https://learn.microsoft.com/en-us/ef/core/saving/execute-insert-update-delete#executeupdate

context.Blogs
    .Where(b => b.Rating < 3)
    .ExecuteUpdate(setters => setters.SetProperty(b => b.IsVisible, false));

The API does this with 2 approaches:

  • the setter and the constant value are specified separately with 2 different Expressions
  • multiple properties can be called in the builder, allowing setting multiple properties

What do you think? Do you see that this API would fit linq2db with another overload?

@jods4
Copy link
Contributor

jods4 commented Jul 31, 2023

Merge might be an exception, but most other operations have such api, for example:

db.Table
  .Set(x => x.Field1, 10)
  .Set(x => x.Field3, x => x.Field1 + x.Field2)
  .Update();

@dtila
Copy link
Author

dtila commented Aug 1, 2023

Thank you @jods4 , indeed I missed those since I have been using just the Merge statements :)

So I would be happy make a PR but I have issues with local development. After installing multiple .NET Full developer packs, I still miss it seems .NET4.5 where I can not find anywhere in the Microsoft.

Neither an article or some documentation I could find, so I don't have the solution working in VS2022.

BTW, are you aware of why an old pack is needed?

@jods4
Copy link
Contributor

jods4 commented Aug 1, 2023

As of today, linq2db still targets and supports .net 4.5:

<TargetFrameworks>net45;net46;net472;netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>

Installing targeting packs in VS should be enough. You should be able to do that from VS setup, they are listed amongst other options.

Otherwise you can change the target to net7.0 only, just don't forget to NOT push it in the PR.
The project will be built and tested against net45 in CI anyway.

@viceroypenguin
Copy link
Contributor

VS2022 no longer includes the netfx45 developer pack because it is so long out of support, and has so many security issues. You can find the net45 dp in the VS 2019 install, or in the win8 sdk install (https://www.gnostice.com/docs/docstudio_net/guide/_faq_buildinganddeployment_vs2022_and_netframework45.html)

@dtila
Copy link
Author

dtila commented Aug 1, 2023

@viceroypenguin I can confirm that this works with Vs2022. However, on my site running tests does not work anymore

I have created a draft extension: #4239 with modifications needed

I think however the InsertWhenNotMatched should accept a IQueryable and to use the existing Set Methods.

However if tests are not running, it puts me in a position impossible to do it ..

@MaceWindu MaceWindu changed the title Immutable data models are not supported [MERGE] Immutable data models are not supported Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants