Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1032125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:02:06+00:00 2026-05-16T14:02:06+00:00

I’m making a simplistic trivial pursuit game . I’m not sure if (and then

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:02:06+00:00Added an answer on May 16, 2026 at 2:02 pm

    In the EF Designer you could create an entity called Answer and then create entities that derive from answer called GeographyAnswer, EntertainmentAnswer, … using a discriminator AnswerType in the Answer entity. Add the Question entity. Add the association from question to Answer, mark it 1:1. Let EF generate the DDL for your database.

    Now you can do question.Answer to get the Answer for a Question. You can look at the Type of Answer and show the appropriate UI.

    Though, this also begs the question, if it’s a 1:1 correspondence between question and answer, why not have a single entity QuestionAnswer and derive from that to create QuestionAnswerGeography, QuestionAnswerEntertainment, … Now you can pick Questions of a specific type easily: dataContext.QuestionAnswers.ofType<QuestionAnswerGeography>() for example.

    Here’s an Entity Diagram for the case where an answer may be shared by multiple questions:
    alt text

    This model will allow you do a query like this:

      var geographyQuestions = objectContext.Answers.OfType<Geography>().SelectMany(answer => answer.Questions);
    

    The DDL generate by this model is:-

    -- Creating table 'Answers'
    CREATE TABLE [dbo].[Answers] (
        [Id] int IDENTITY(1,1) NOT NULL
    );
    GO
    
    -- Creating table 'Questions'
    CREATE TABLE [dbo].[Questions] (
        [Id] int IDENTITY(1,1) NOT NULL,
        [AnswerId] int  NOT NULL,
        [QuestionText] nvarchar(max)  NOT NULL
    );
    GO
    
    -- Creating table 'Answers_Geography'
    CREATE TABLE [dbo].[Answers_Geography] (
        [PlaceName] nvarchar(max)  NOT NULL,
        [LatLong] nvarchar(max)  NOT NULL,
        [Id] int  NOT NULL
    );
    GO
    
    -- Creating table 'Answers_Entertainment'
    CREATE TABLE [dbo].[Answers_Entertainment] (
        [Name] nvarchar(max)  NOT NULL,
        [BornOn] datetime  NULL,
        [DiedOn] datetime  NULL,
        [Id] int  NOT NULL
    );
    GO
    
    -- --------------------------------------------------
    -- Creating all PRIMARY KEY constraints
    -- --------------------------------------------------
    
    -- Creating primary key on [Id] in table 'Answers'
    ALTER TABLE [dbo].[Answers]
    ADD CONSTRAINT [PK_Answers]
        PRIMARY KEY CLUSTERED ([Id] ASC);
    GO
    
    -- Creating primary key on [Id] in table 'Questions'
    ALTER TABLE [dbo].[Questions]
    ADD CONSTRAINT [PK_Questions]
        PRIMARY KEY CLUSTERED ([Id] ASC);
    GO
    
    -- Creating primary key on [Id] in table 'Answers_Geography'
    ALTER TABLE [dbo].[Answers_Geography]
    ADD CONSTRAINT [PK_Answers_Geography]
        PRIMARY KEY CLUSTERED ([Id] ASC);
    GO
    
    -- Creating primary key on [Id] in table 'Answers_Entertainment'
    ALTER TABLE [dbo].[Answers_Entertainment]
    ADD CONSTRAINT [PK_Answers_Entertainment]
        PRIMARY KEY CLUSTERED ([Id] ASC);
    GO
    
    -- --------------------------------------------------
    -- Creating all FOREIGN KEY constraints
    -- --------------------------------------------------
    
    -- Creating foreign key on [AnswerId] in table 'Questions'
    ALTER TABLE [dbo].[Questions]
    ADD CONSTRAINT [FK_QuestionAnswer]
        FOREIGN KEY ([AnswerId])
        REFERENCES [dbo].[Answers]
            ([Id])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_QuestionAnswer'
    CREATE INDEX [IX_FK_QuestionAnswer]
    ON [dbo].[Questions]
        ([AnswerId]);
    GO
    
    -- Creating foreign key on [Id] in table 'Answers_Geography'
    ALTER TABLE [dbo].[Answers_Geography]
    ADD CONSTRAINT [FK_Geography_inherits_Answer]
        FOREIGN KEY ([Id])
        REFERENCES [dbo].[Answers]
            ([Id])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    GO
    
    -- Creating foreign key on [Id] in table 'Answers_Entertainment'
    ALTER TABLE [dbo].[Answers_Entertainment]
    ADD CONSTRAINT [FK_Entertainment_inherits_Answer]
        FOREIGN KEY ([Id])
        REFERENCES [dbo].[Answers]
            ([Id])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.