Linq query with a Join, not returning the correct results?

Given that you want the logs, try this simplified-for-demo-only code: string optionalGameType = "COD4"; //retrieve log entries for BANNED, with optional specified game type List banned = logs. Where(x => x. EventType == "banned") .

WhereIf(optionalGameType. Length > 0, (x => x. GameFileID == games.

Where(g => g. GameType == optionalGameType).SingleOrDefault(). GameFileID)) .ToList(); int cod4BannedCount = banned.

Count; return banned I used a string instead of your custom type, and a string instead of your EventType. BannableViolation. It'd be easy for you to use your custom types instead The full source/proof is at this pastebin page Check out the WhereIf extension method It's helped me a few times to avoid those conditionals as separate statements Given that example, your code might be refactored to look something like this: List banned = _logEntryRepository.GetLogEntries() .

Where(x => x. EventType == EventType. BannableViolation) .

WhereIf(gameType. HasValue, (x => x.GameFile. GameType == _gamefileRepository.GetGameFiles() .

Where(g => g. GameType == gameType) .SingleOrDefault() . GameType )) .ToList().

Given that you want the logs, try this simplified-for-demo-only code: string optionalGameType = "COD4"; //retrieve log entries for BANNED, with optional specified game type List banned = logs. Where(x => x. EventType == "banned") .

WhereIf(optionalGameType. Length > 0, (x => x. GameFileID == games.

Where(g => g. GameType == optionalGameType).SingleOrDefault(). GameFileID)) .ToList(); int cod4BannedCount = banned.

Count; return banned; I used a string instead of your custom type, and a string instead of your EventType. BannableViolation. It'd be easy for you to use your custom types instead.

The full source/proof is at this pastebin page. Check out the WhereIf extension method. It's helped me a few times to avoid those conditionals as separate statements.

Given that example, your code might be refactored to look something like this: List banned = _logEntryRepository.GetLogEntries() . Where(x => x. EventType == EventType.

BannableViolation) . WhereIf(gameType. HasValue, (x => x.GameFile.

GameType == _gamefileRepository.GetGameFiles() . Where(g => g. GameType == gameType) .SingleOrDefault() .

GameType )) .ToList().

Hmm. Interesting :) I like this WhereIf extension method. Problem with this code is, with this part .

WhereIf(gameType. HasValue, (x => x. GameType == )) won't/doesn't work .. because x` is representing a LogEntry .. which doesn't have a property called GameType ... that exists on a GameFile type.

– Pure. Krome Dec 19 '09 at 7:23 @ PCambell - thanks for the code update. Still doesn't compile.

I'm sure it's because the x => x. Represents a logEntry variable .. which doesn't have a reference up to a GameFile.....? Maybe a JOIN is required? – Pure.

Krome Dec 19 '09 at 22:31 even though this still didn't work for me, i'll give it a tick cause it was pretty close / good / inspiring :) – Pure. Krome Jan 3 '10 at 3:49.

This can occur because the Entity Framework translates a query against a conceptual model into an equivalent query against the data source. When a single entity set in the conceptual model maps to more than one table in the data source, or when a relationship between entities is mapped to a join table, the query command executed against the data source query may require one or more joins. Use the ToTraceString method of the ObjectQuery or EntityCommand classes to view the commands that are executed against the data source for a given query.

For more information, see How to: View the Store Commands (Entity Framework). Nested Entity SQL queries may create joins on the server and can return a large number of rows. SELECT c, (SELECT c, (SELECT c FROM AdventureWorksModel.

In addition, such queries cause the query pipeline to generate a single query with duplication of objects across nested queries. Because of this, a single column may be duplicated multiple times. On some databases, including SQL Server, this can cause the TempDB table to grow very large, which can decrease server performance.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions