How to set comment on JSON column
Ask a question
How to set comment on JSON column
Include your code
I tried use CommentAttribute , but doesn't work.
public class JsonTable{
...
[Comment("xxx")]
public SampleJsonDataType Data {get;set;}
}
[Comment("xxx")]
public class SampleJsonDataType {
...
...
}
class JsonTableEntityConfiguration: IEntityTypeConfiguration<JsonTable>
{
public void Configure(EntityTypeBuilder<JsonTable> builder){
builder.OwnsOne(p => p.Data, ownedNavigationBuilder =>
{
ownedNavigationBuilder.ToJson();
}
}
}
Include provider and version information
EF Core version: 8 Database provider: Microsoft.EntityFrameworkCore.SqlServer
Currently JSON entities are internally mapped using owned types, which don't allow setting comment on them. Once we enable mapping JSON using complex types, this should light up "for free". https://github.com/dotnet/efcore/issues/31252
On top of that we could consider adding this for owned types also, We have SetContainerColumnName, could add SetContainerColumnComment or something similar, and expose it via ToJson @AndriySvyryd thoughts?
We already allow setting table comments for owned types, we can reuse the same metadata for JSON column comment.