我有一个包含这些列(类型)的表,如下所述。
桌子
------------------------------------------------------------------
Dir(str) | Twnshp(int) | Rng(int) | Section(int) | Xcell(int) | Ycell(int)
------------------------------------------------------------------
我正在尝试使用 EF 进行此查询。
SELECT Xcell,Ycell FROM [CIR].[dbo].[TRS2Cell] where Twnshp = 1 and Rng = 4 and Section =31
经过一番研究,我创建了一个 DAL 上下文和类,如下所示。
PlotXYContext.cs
public class PlotXYContext :DbContext
{
public DbSet<PlotXY> XYCells { get; set; }
}
绘图XY.cs
[Table("TRS2Cell")]
public class PlotXY
{
public string Dir { get; set; }
[Key]
public int Twnshp { get; set; }
public int Rng { get; set; }
public int Section { get; set; }
public int Xcell { get; set; }
public int Ycell { get; set; }
}
这是我的控制器中的代码,我在其中传递了三个参数。
PlotXYContext plotXYContext = new PlotXYContext();
var query = from TRS2Cell in plotXYContext.XYCells
where TRS2Cell.Twnshp == 1
&& TRS2Cell.Rng == 4
&& TRS2Cell.Section == 31
select TRS2Cell.Xcell;
我需要 EF 方面的帮助,因为我是新手,这也是正确的查询吗?如果是这样,我如何从查询中检索 Xcell 和 Ycell 值。此外,该表没有唯一列,没有空值,这里不需要更新任何内容。我只想做一个选择。