efcore icon indicating copy to clipboard operation
efcore copied to clipboard

How to set comment on JSON column

Open tai-yi opened this issue 1 year ago • 2 comments

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

tai-yi avatar Mar 22 '24 02:03 tai-yi

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?

maumar avatar Apr 11 '24 02:04 maumar

We already allow setting table comments for owned types, we can reuse the same metadata for JSON column comment.

AndriySvyryd avatar May 02 '24 01:05 AndriySvyryd