question

AGMohamed-3618 avatar image
0 Votes"
AGMohamed-3618 asked GustavoMelendez-6351 commented

The JSON value could not be converted to System.String. Path: $[1].Interests[1].Meta[9].Content | LineNumber: 0 | BytePositionInLine: 10073. Error

 public Class Emp{
    
 public string Name  { get; set; }
    
    
   [Column(TypeName = "jsonb")]
  public List<Section> Sections { get; set; }
    
 }
    
 public Class Section{
    
    public string Booking { get; set; }
    
    
  [Column(TypeName = "jsonb")]
   public List<Interest> Interests { get; set; }
    
 }
    
 public Class Interests{
    
  public string Title { get; set; }
    
  public List<Meta> Meta { get; set; }
    
    
  public List<WithAlt> Images { get; set; }
 }
    
 public Class Meta{
    
          public string Type { get; set; }
    
         public string Content { get; set; }
    
 }
    
 public Class WithAlt{
    
          public string content { get; set; }
    
         public string Alt { get; set; }
    
 }

I fetch data from the above table

Emp while fetching the data I got
The JSON value could not be converted to System.String. Path: $[1].Interests[1].Meta[9].Content | LineNumber: 0 | BytePositionInLine: 10073. Error

When I manually add the value to database bellow

  {
         "Booking": "",
         "Interests":[
     {
         "Title":"",
    
        "Meta":[
 `         {
              "Type" : " ",
    
               "Content" : " "
    
    
      `   }
        ],
    
       "Images" : [
          {
             "content" : " ",
             "alt" : " "
    
          }
    
     ]
    
    
      }
 ],         
    
 }

it will not throw the error

Are there any way to define the default value to the above fields using code first approach


when I initialize Sections property like

public List<Section> Sections { get; set; }={};

it shows the following error


Can only use array initializer expressions to assign to array types. Try using a new expression instead.







dotnet-csharpdotnet-entity-framework-coredotnet-entity-framework
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered GustavoMelendez-6351 commented

See the following for setting a default value for a property


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The question is not for EF
Is about Json

0 Votes 0 ·