.net working with list stored in one column give me error

32 Views Asked by At

I have Cards in databse, in cards table:

List<CardItem> Items

in CardItem:

List<CardItemContent> ContentItems

in CardItemContent:

string ItemKey

in the database configuration, I have:

builder.ToTable(
    "Cards"
);

builder.Property(e => e.Items)
    .HasConversion(
        o =>
            JsonConvert
            .SerializeObject(
            o,
            new JsonSerializerSettings()
            ),
        o =>
            JsonConvert
            .DeserializeObject<List<CardItem>>(
            o,
            new JsonSerializerSettings()
            )!
    )

This will store the list as json in database in one column

now I tried the following code:

var query =
    from card in dbContext.Cards
    where
    card.Items
        .Exists(
            c => c.ContentItems.Exists(ci => ci.ItemKey != null)
        )
    select card;

I got error:

The LINQ expression 'c => c.ContentItems.Exists(ci => ci.ItemKey != null)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'

0

There are 0 best solutions below