使用linq查询从多个故事中选择数据

时间:2018-05-26 09:22:29

标签: linq

我有2个表我想从表1中选择所有记录但是在第二个表中我想要选择id基础上id与表1无关的所有记录。我想在linq查询中执行此操作。 任何帮助

1 个答案:

答案 0 :(得分:0)

据我所知,您想在两个表之间进行联接:

var query = database.FirstTable                                                             // starting point - the first table from your question
                    .Join(database.SecondTable,                                             // the second table
                              first => first.ID,                                            // Select the primary key (the first part of the "on" clause in an sql "join" statement)
                              second => second.first_ID,                                    // Select the foreign key (the second part of the "on" clause)
                              (first, second) => new { First = first, Second = second })    // selection
                    .Where(result => result.first.ID == id);                                // where statement