实体框架不包括select语句中的列

时间:2014-02-24 08:00:15

标签: c# sql entity-framework

我刚刚在实体框架已映射的表中添加了一列。实体框架将列添加到模型中,但不包括其中的列的选择查询。这是EF生成的类:

public partial class mj_bagasse_gc_sampledetail
{
    public long ID { get; set; }
    public Nullable<double> FructoseArea { get; set; }
    public Nullable<double> SucroseArea { get; set; }
    public Nullable<double> GlucoseArea { get; set; }
    public Nullable<double> TrehaloseArea { get; set; }
    public Nullable<double> SampleWeight { get; set; }
    public Nullable<double> TrehaloseWeight { get; set; }
    public string TriplicateIndex { get; set; }
    public Nullable<long> Sample_ID { get; set; }
    public Nullable<double> FructoseConc { get; set; }
    public Nullable<double> SucroseConc { get; set; }
    public Nullable<double> GlucoseConc { get; set; }
    public Nullable<int> GCIndex { get; set; }
    public string BottleNo { get; set; }
    public Nullable<bool> SelectedSampleDetail { get; set; }
    public Nullable<int> SampleDetailRun { get; set; }

    public virtual global_global_sample global_global_sample { get; set; }
}

这是EDMX文件中映射的XML:

<EntityType Name="mj-bagasse_gc_sampledetail">
      <Key>
        <PropertyRef Name="ID" />
      </Key>
      <Property Name="ID" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" />
      <Property Name="FructoseArea" Type="float" />
      <Property Name="SucroseArea" Type="float" />
      <Property Name="GlucoseArea" Type="float" />
      <Property Name="TrehaloseArea" Type="float" />
      <Property Name="SampleWeight" Type="float" />
      <Property Name="TrehaloseWeight" Type="float" />
      <Property Name="TriplicateIndex" Type="varchar" MaxLength="2" />
      <Property Name="Sample_ID" Type="bigint" />
      <Property Name="FructoseConc" Type="float" />
      <Property Name="SucroseConc" Type="float" />
      <Property Name="GlucoseConc" Type="float" />
      <Property Name="GCIndex" Type="int" />
      <Property Name="BottleNo" Type="varchar" MaxLength="20" />
      <Property Name="SelectedSampleDetail" Type="bit" />
      <Property Name="SampleDetailRun" Type="int" />
    </EntityType>

你会在两个实例中清楚地注意到#34; SampleDetailRun&#34;是正确定义的。但是,当我尝试使用LINQ语句从表中获取一行时:

(from sd in Entities.mj_bagasse_gc_sampledetail 
                                  where (sd.Sample_ID == Sample.ID) && 
                                  (sd.TriplicateIndex == s) select sd).FirstOrDefault();

此SQL语句执行:

exec sp_executesql N'SELECT TOP (1) 
[Extent1].[ID] AS [ID], 
[Extent1].[FructoseArea] AS [FructoseArea], 
[Extent1].[SucroseArea] AS [SucroseArea], 
[Extent1].[GlucoseArea] AS [GlucoseArea], 
[Extent1].[TrehaloseArea] AS [TrehaloseArea], 
[Extent1].[SampleWeight] AS [SampleWeight], 
[Extent1].[TrehaloseWeight] AS [TrehaloseWeight], 
[Extent1].[TriplicateIndex] AS [TriplicateIndex], 
[Extent1].[Sample_ID] AS [Sample_ID], 
[Extent1].[FructoseConc] AS [FructoseConc], 
[Extent1].[SucroseConc] AS [SucroseConc], 
[Extent1].[GlucoseConc] AS [GlucoseConc], 
[Extent1].[GCIndex] AS [GCIndex], 
[Extent1].[BottleNo] AS [BottleNo]
FROM [dbo].[mj-bagasse_gc_sampledetail] AS [Extent1]
WHERE ([Extent1].[Sample_ID] = @p__linq__0) AND ([Extent1].[TriplicateIndex] = @p__linq__1)',N'@p__linq__0 bigint,@p__linq__1 varchar(8000)',@p__linq__0=127,@p__linq__1='A'
go

select语句中缺少SampleDetailRun列,我无法弄清楚如何让它包含它。我尝试删除映射表并重新添加它。我已经尝试从数据库中的表中删除该列并重新添加它(即使使用不同的名称)但是没有任何内容可以使EF包含该列中的列。

我正在使用EF5

有什么想法吗?感谢

1 个答案:

答案 0 :(得分:0)

叹息。使用EF数据上下文的项目的EF元数据文件(* .msl,* .csdl和* .ssdl)位于与重建EF项目时更新的文件夹不同的文件夹中。当我将它们复制到使用文件的项目时,它包含了select语句中的列。