I want to query a sql server database using Linq to Entities. I want to filter the results using the following Sql Query against the following tables:
DECLARE p0...
SELECT * FROM Boards b
WHERE b.ownerid = p0 or
b.id IN (SELECT s.boardid FROM Shares s WHERE s.userid = p0)
CREATE TABLE [dbo].[Boards] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[OwnerId] NVARCHAR (128) NULL,
[ShortName] NVARCHAR (50) NULL,
...);
CREATE TABLE [dbo].[Shares] (
[BoardId] INT NOT NULL,
[UserId] NVARCHAR (128) NOT NULL
);
A couple caveats, there will be at least one Board row. There can be zero to many Share rows. I want to return the one Board row, and any additional Board rows that have linked Share rows.
I have performed the query using a GroupJoin, SelectMany, and DefaultIfEmpty in effort to perform the equivalent TSQL Outer JOIN but all of those seem way more complex than the TSql equivalent.
How can I perform the equivalent in Linq to filter results such that it uses "Where In" SQL statement and an OR clause with data in the parent table?