2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

自作クラスとEntityFrameworkをLinqで一度に結合出来ない

Posted at

EntityFrameworkを勉強したてで、色々やっているのだけれど、EntityFrameworkのテーブルクラスと自作クラスを結合しようとしたら、ToList()の部分でエラーになる。

エラーになるコード
Dim a = From t In _ef.DB_Table
        Join c In EnumableMyClass
        On t.Key1 Equals c.MyClassKey1

Dim a_list = a.ToList()
Exception
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Additional information: Unable to create a constant value of type 'XXXXX'. Only primitive types or enumeration types are supported in this context.

解決策は、EntytiFrameworkのLinq結合はEntityFrameworkだけででやり、その後、自作クラスと結合するやり方でないとダメである結論に至った。

エラーにならないコード
'EntityFrameworkテーブルと自作クラスは別々に扱う
Dim a = From t In _ef.DB_Table
Dim a_list = a.ToList()

Dim b = From t In a_list
        Join c In EnumableMyClass
        On t.Key1 Equals c.MyClassKey1

Dim b_list = b.ToList()
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?