Hi folks,
I'm making a simplistic trivial pursuit game. I'm not sure if (and then how) I can do the following with EF4 :-
I have a table structure as follows.
Table: TrivialPursuitQuestion
=> ID
=> Unique Question
=> AnswerId
=> AnswerType (ie. Geography, Entertainment, etc).
Table: GeographyAnswer
=> ID
=> Place Name
=> LatLong
Table: EntertainmentAnswer:
=> ID
=> Name
=> BordOn
=> DiedOn
=> Nationality .. and other meta data
... etc ..
So when a person asks a unique question ... the stored proc is able to figure out what type of answer it is (ie. AnswerType field) ... and therefore query against the correct table.
EG.
SELECT @AnswerId = AnswerId, @AnswerType = AnswerType
FROM TrivialPursuitQuestions
WHERE UniqueQuestion = @Question
IF @AnswerId > 0 AND @AnswerType > 0 BEGIN
IF @AnswerType = 1
SELECT *
FROM GeographicAnswers
WHERE AnswerId = @AnswerID
IF @AnswerType = 2
SELECT *
FROM EntertainmentAnswer
WHERE AnswerId = @AnswerId
... etc ...
END
Now .. i'm not sure how to do this with EF. First of all, the stored proc can now return MULTIPLE result types .. so i'm not sure if that's really really bad.
So then I thought, maybe the stored procedure should return Multiple Recordsets .. with all but one recordset containing result(s) ... because by design, only one answer type will ever be found...
EG.
-- Same SELECT as above...
IF @AnswerId > 0 BEGIN
SELECT *
FROM GeographicAnswers
WHERE AnswerId = CASE @AnswerId WHEN 1 THEN @AnswerID ELSE 0 END
SELECT *
FROM EntertainmentAnswer
WHERE AnswerId = CASE @AnswerId WHEN 2 THEN @AnswerID ELSE 0 END
... etc ...
END
and this will return 6 (multiple) recordsets ... but only one of these should ever have some data.
Now, if this is a better solution ... is this possible with EF4 and how?
I'm trying to avoid doing TWO round trips to the db AND also having to figure out WHAT to try and retrieve ... i don't want to have to figure it out .. i'm hoping with some smart modelling the system is just smart enough to say 'OH! u this is the right answer'. Sort of like a Answer Factory (ala Factory Pattern) but with Sql Server + EF4.
ANyone have any ideas?