12

当我尝试加入表格时

var query =
    from foo in db.Foos
    from bar in db.Bars
    where foo.ID == bar.FooID
    where foo.ID == 45
    select bar;


query.toArray()

我收到这样的错误

Unable to create a constant value of type 'Bar'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
4

1 回答 1

24

试试这个:

var query =
    from foo in db.Foos
    join bar in db.Bars on foo.ID equals bar.FooID
    where foo.ID == 45
    select bar;

无论如何,我建议您在 EDM 设计器中对 Foo 和 Bar 之间的关系进行建模,这样您就不需要显式连接:

var query =
    from foo in db.Foos
    where foo.ID == 45
    from bar in foo.Bars
    select bar;
于 2011-02-25T00:21:18.727 回答