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

strongly typing IDs using implicit operator? #681

Open
jakobadam opened this issue Mar 9, 2023 · 0 comments
Open

strongly typing IDs using implicit operator? #681

jakobadam opened this issue Mar 9, 2023 · 0 comments

Comments

@jakobadam
Copy link

jakobadam commented Mar 9, 2023

I was trying to replace an id long with a more informative type, using the following approach:

[TableName("Agreement")]
[PrimaryKey("Id")]
 public class Agreement
{
  public AgreementId Id { get; set;  } // a bigint in the db
       
   // ...
}
public class AgreementId
{
    private readonly long _value;

    public AgreementId(long value)
    {
        _value = value;
    }

    public static implicit operator long(AgreementId id) => id._value;

    public static implicit operator AgreementId(long value) => new AgreementId(value);
}

However, after that change the id property is not populated (is null)

db.Query<Agreement>().First() // id is null after change...

Is something like this possible?

By the way, the chat channel domain has been 'hijacked' by some bogus site.

kind regards,
Jakob

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