Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何使用实体框架添加带有外键的记录?_Sql_Linq_Sql Server 2008_Entity Framework_Entity Framework 4.1 - Fatal编程技术网

Sql 如何使用实体框架添加带有外键的记录?

Sql 如何使用实体框架添加带有外键的记录?,sql,linq,sql-server-2008,entity-framework,entity-framework-4.1,Sql,Linq,Sql Server 2008,Entity Framework,Entity Framework 4.1,我试图通过如下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" Produc

我试图通过如下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>

请检查一下图表。我需要获取一些数据,以便将记录添加到考试生成表、练习表和答案表(实体)

在考试中,我有一个字段叫做ExamID hide。我的主要问题是,如何将当前文件引用到考试中

您认为我需要创建一个存储过程,而SQL SERVER必须这样做吗? 还是使用LINQtoSQL

我对这种情况有点困惑


您可以将
ExamProduced
实例添加到
ExamProduced
ExamProduced
集合中。DbContext将在插入时设置ExamId。

您可以将
ExamProduced
实例添加到
ExamProduced
ExamProduced
集合中。DbContext将在插入时设置ExamId。

Registries=records,我假定。Registries=records,我假定。ExamProduced实例应添加到ExamProduced表中,对吗?ExamProduced实例应添加到ExamProduced表中,对吗?