1

As the Title says i defined my member, for example my Id, as an Observable Property with the CommunityToolKit.MVVM

[ObservableProperty]
private int id;

But now i am trying to give my Observable Property [PrimaryKey,AutoIncrement] from the SQLite Extension. But i cant just write it like that cause we have no self defined Get/Set only the generated one. Is there a way to add that annotation while it still is an ObservableProperty?

I Imagine it something like that:

[ObservableProperty]
[PrimaryKey, AutoIncrement]
private int id;
Kioshia
  • 13
  • 4

1 Answers1

0

When you need an extra annotation with [ObservableProperty], (that is not part of the toolkit itself), you have to prefix it with "property:".

So your property could be written like this:

[ObservableProperty]
[property: PrimaryKey]
[property: AutoIncrement]
private int id;

This way your property will be generated with the PrimaryKey and AutoIncrement attributes over it.

See also: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/observableproperty, under "Adding custom Attributes"

Dawied
  • 897
  • 10
  • 16