2

我想通過XML文件將記錄添加到我的數據庫像這樣的:如何使用實體框架添加帶有外鍵的記錄?

<Answers ExamID="1" StudentID="abcd" Date="10/26/2011 11:50:34 AM" Seed="495" 
     IsSED="False"> 
    <Summary> 
    <Objective ID="1" MakeUp="False" Quantify="5" Difficulty="Easy" 
     Accredited="True" Produced="True"> 
     <Details Result="0" Date="10/26/2011 11:35:18 AM" /> 
     <Details Result="1" Date="10/26/2011 11:50:34 AM" /> 
    </Objective> 
    <Objective ID="2" MakeUp="True" Quantify="5" Difficulty="Easy" 
     Accredited="False" Produced="True"> 
     <Details Result="0" Date="10/26/2011 11:35:18 AM" /> 
     <Details Result="0" Date="10/26/2011 11:50:34 AM" /> 
    </Objective> 
    </Summary> 
    <Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="9" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="20" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="16" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="36" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="18" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="Null" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="Null" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="Null" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="Null" /> 
    </Answer> 
    <Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy"> 
    <Result DataType="System.Decimal" Value="Null" /> 
    </Answer> 
</Answers> 

請檢查圖。我需要獲取一些數據以將記錄添加到EXAM PRODUCED,EXERCISE和ANSWER表(實體)中。

在考試製作中,我有一個名爲ExamID hide的字段。我的主要問題是,我怎樣才能將當前文件引用到考試中?

你認爲我需要創建一個存儲過程,SQL SERVER必須這樣做嗎? 或使用Linq to SQL?

我對這種情況有點困惑。

enter image description here

+0

註冊=記錄,我假設。 – 2011-12-13 21:19:15

+0

究竟是這樣的 – Darf 2011-12-13 21:20:48

回答

0

您可以在ExamProduced實例添加到收藏ExamsProducedExam。 DbContext將在插入時設置ExamId。