With ignoring-dto-properties, is there any way to rather set a class to be otp in with an [Include] attribute or something rather than adding [Ignore] onto properties?
We often find this is cause for developer error whereby people forget to put the [Ignore] attribute onto properties whereas the properties that should be included don’t change.
public partial class User
{
[Alias("UserId")]
[AutoIncrement]
public int Id { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public DateTime DateOfBirth { get; set; }
}
public partial class User
{
[Ignore]
public string FriendlyName { get => FirstName + " " + LastName; }
[Ignore]
public string FormattedDateOfBirth { get => DateOfBirth.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture); }
}
We then add many other properties onto the partial classes and having to add [Ignore] each time is a huge potential for error.
When it would be good to have something similar to this:
[OrmliteOtpIn]
public partial class User
{
[Alias("UserId")]
[AutoIncrement]
[Include]
public int Id { get; set; }
[Required]
[Include]
public string FirstName { get; set; }
[Required]
[Include]
public string LastName { get; set; }
[Required]
[Include]
public DateTime DateOfBirth { get; set; }
}
public partial class User
{
public string FriendlyName { get => FirstName + " " + LastName; }
public string FormattedDateOfBirth { get => DateOfBirth.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture); }
}
There’s no opt-in for OrmLite, for DTOs you can opt-in with [DataContract]/[DataMember] attributes.
I’d recommend using a different convention for non persisted properties like Methods:
public string FriendlyName() => FirstName + " " + LastName;
Even better, put it in an Extension method (instead of a partial) decoupled from your class so there’s a clear distinction that naturally wont get treated as or confused for persisted properties.
Wont be adding that feature, it’s too verbose/ugly & will rarely to ever get used.