efcore icon indicating copy to clipboard operation
efcore copied to clipboard

EF core 7 JSON column gives error for List<Guid>

Open kdehia opened this issue 3 years ago • 1 comments

"The entity type 'List' requires a primary key to be defined"

After configuring the JSON column setup I get the following error "The entity type 'List' requires a primary key to be defined"

Here is my entities

public class CheckpointJSON 
{
public ActivityJSONDto JsonData { get; set; }
}

public class ActivityJSONDto
{
public List<ResponseCollectionDto> ActivityDetailJson { get; set; }
}


public class ResponseCollectionDto
{
public List<GotoConditionDto> GotoConditions { get; set; } = new();
}

public class GotoConditionDto
{
public string GotoAnswer { get; set; }
public List<Guid> Goto { get; set; } = new();
}

here is the model builder

modelBuilder.Entity< CheckpointJSON >()
            .OwnsOne(c=> c.JsonData,
            builder=>
            {
                builder.OwnsMany(AC => AC.ActivityDetailJson,
                    bu =>
                    {
                        //bu.Property(c => c.GotoConditions);
                        bu.OwnsMany(c => c.GotoConditions
                            , builder =>
                            {
                                builder.ToJson();
                            }
                            );
                        bu.Property(c=>c.ResponseCustomTypeId).HasConversion<int>();
                        bu.OwnsMany(c => c.ResponseOptions,b=>
                        {
                            //b.HasKey(c => c.ResponseOptionDtoId);
                        });
                        bu.OwnsMany(c => c.InspectionResult,builder =>
                        {
                            builder.OwnsMany(c => c.CollectionOptionDtos);
                            builder.OwnsMany(c => c.ImageCollectionDtos);
                            builder.ToJson();
                        });
                        bu.ToJson();
                    });
                
                builder.ToJson();
            });

kdehia avatar Aug 11 '23 22:08 kdehia

Duplicate of #31364

ajcvickers avatar Aug 17 '23 12:08 ajcvickers