NPoco icon indicating copy to clipboard operation
NPoco copied to clipboard

strongly typing IDs using implicit operator?

Open jakobadam opened this issue 1 year ago • 0 comments

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

jakobadam avatar Mar 09 '23 14:03 jakobadam