LoginSignup
0
0

EF Core 7.0から利用可能なJSON列を使おうとして"ndex was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')"

Posted at

変にハマったので記録

EFCore7から使えるようになったJSON列

モデル

public class Customer
{
    public string Name { get; set; }
    public Status Status { get; set; }
}

public class Status
{
    // これはJSONマッピングする
    public CustomerAdditionalDetail Detail { get; set; }
}


public class CustomerAdditionalDetail
{
    // 後で定義しようとした
}

みたいな感じで、(modelbuilderのあたりは省略)
で、includeすると

 context.Customers
            .Include(c => c.Status);

エラーが発生

System.ArgumentOutOfRangeException
Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

デバッグ見るとクエリの発行すらされていない、なので何かリレーションが間違ってるのか…
と見直したが特におかしいところはない。

原因

後で中身を定義しようとしたCustomerAdditionalDetailが原因だった。
とりあえず適当なプロパティを入れると問題なく出るようになった。
(いろいろググってもわからなかったので記録のため記事にしておいた)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0