NPoco
NPoco copied to clipboard
strongly typing IDs using implicit operator?
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