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

HiLo generated values #76

Open
ealeykin opened this issue Jul 13, 2022 · 1 comment
Open

HiLo generated values #76

ealeykin opened this issue Jul 13, 2022 · 1 comment

Comments

@ealeykin
Copy link

ealeykin commented Jul 13, 2022

Hi,

I have an issue with Hilo value generated property, it always set as 0.

I noticed in your source code there is an Address entity with Hilo property commented out, why? I got the same property in my entity that doesn't work. It's not a shadow property (shadow properties don't work neither), is it supported at all?

Have to say it was working with EF Core 2, but after upgrading to 3.1 - property always has default value 0.

Thanks

@ealeykin
Copy link
Author

ealeykin commented Jul 16, 2022

If the property is not a Primary key or part of a composite primary key then you must add HasAlternateKey(...) for the target property in order to use HiLo at least since EF Core 3.

Other than that what is related to the library - if you disable change tracking in BulkUploader with second constructor parameter - then it still won't generate values. Could you please consider adding something like this

if (infos.PropertyNameToGenerators == null ||
                infos.PropertyNameToGenerators.Count == 0 ||
                disableEntitiesTracking)
            {
                if (disableEntitiesTracking && infos.PropertyNameToGenerators != null)
                {
                    foreach (var item in entities)
                    {
                        foreach (var map in infos.PropertyToGenerators)
                        {
                            var localValue = map.Key.PropertyInfo.GetValue(item);

                            if (map.Key.PropertyInfo.PropertyType.IsDefaultValue(localValue))
                            {
                                map.Key.PropertyInfo.SetValue(item, map.Value.Next(null));
                            }
                        }
                    }
                }
                
                return;
            }

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