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

Non-string ID column not fully supported #113

Open
tunger opened this issue Jul 13, 2020 · 0 comments
Open

Non-string ID column not fully supported #113

tunger opened this issue Jul 13, 2020 · 0 comments

Comments

@tunger
Copy link
Contributor

tunger commented Jul 13, 2020

Quickstart states that
The only assumption is that you'll provide an "Id" property which is a string (though it doesn't have to be a string).

Unfortunately, there is not yet full support for IDs of other types. I tried adding support to Nevermore by changing string casts and parameters to object, but ran into problems with method overload resolution, so I'm not certain if that's the right way.

Problem 1
.Load methods only accept string. Therefore, to load entities of other types, one needs to work around by using .Query

Problem 2
Insert fails because Id column is cast to string.
https://github.com/OctopusDeploy/Nevermore/blob/master/source/Nevermore/Util/DataModificationQueryBuilder.cs#L246

Workaround: use a property handler for ID column that casts to string on Read

    public class ReportStateCorrelationIdPropertyHandler : IPropertyHandler
    {
        public object Read(object target)
        {
            return ((ReportState)target).CorrelationId.ToString();
        }

        public void Write(object target, object value)
        {
            var state = (ReportState)target;
            Guid guid = default;
            if (value != null)
            {
                if (value.GetType() == typeof(Guid))
                    guid = (Guid)value;
                else if (value.GetType() == typeof(string))
                    guid = Guid.Parse((string)value);
            }

            state.CorrelationId = guid;
        }
    }

Would be great if Nevermore could handle it. I can submit WIP PR if you want, and you can point me into right direction.

Use case is using Nevermore as MassTransit Saga repository, which uses GUIDs as correlation id.

tunger added a commit to tunger/Nevermore that referenced this issue Jul 15, 2020
tunger added a commit to tunger/Nevermore that referenced this issue Jul 19, 2020
PaulStovell added a commit that referenced this issue Aug 20, 2020
#113 Improve support for non-string ID columns
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