我已经尝试了互联网,但找不到一个好的答案。这是有问题的代码
private void LoadRecords()
{
var data = from record in model.Records
where record.TimeStamp >= oldestRecordVisible
orderby record.TimeStamp descending
select record;
dataGridView1.DataSource = data.ToList();
}
我正在为数据库使用 mySql 服务器。这是来自 context.cs 的代码
using System.Data.Entity;
namespace MilThicknessMonitor3.Models
{
public class DataModel : DbContext
{
public DataModel()
: base("name=DataConnection")
{
}
public DbSet<Record> Records { get; set; }
public DbSet<CaptureSource> CaptureSources { get; set; }
public DbSet<PlcConfiguration> PlcConfigurations { get; set; }
public DbSet<Configuration> Configurations { get; set; }
}
}
任何帮助将不胜感激
下面是数据模型
using MilThicknessMonitor3.Analytics;
using System;
using System.ComponentModel;
namespace MilThicknessMonitor3.Models
{
public class Record
{
public int Id { get; set; }
[DisplayName("Date/Time")]
public DateTime TimeStamp { get; set; }
[DisplayName("Average Measure (Mils)")]
public double AvgMeasure { get; set; }
[DisplayName("Average Measure (Millimetres)")]
public double AvgMilli { get { return AvgMeasure / 39.37; } }
[DisplayName("Minimum Measure (Mils)")]
public double MinMeasure { get; set; }
[DisplayName("Minimum Measure (Millimetres)")]
public double MinMilli { get { return MinMeasure / 39.37; } }
[DisplayName("Maximum Measure (Mils)")]
public double MaxMeasure { get; set; }
[DisplayName("Maximum Measure (Millimetres)")]
public double MaxMilli { get { return MaxMeasure / 39.37; } }
[DisplayName("Notes")]
public string Notes { get; set; }
#region Testing Fields, Properties, and Methods
private DataLine offset;
internal DataLine Offset
{
get { return offset; }
}
private DataLine baseline;
internal DataLine Baseline
{
get { return baseline; }
}
private float[] results;
public int[] OffsetValues
{
get
{
int[] values = new int[offset.Size];
int index = 0;
foreach (ImageColumn c in offset)
{
values[index] = c.Ys.Count;
index++;
}
return values;
}
}
public int[] BaselineValues
{
get
{
int[] values = new int[baseline.Size];
int index = 0;
foreach (ImageColumn c in baseline)
{
values[index] = c.Ys.Count;
index++;
}
return values;
}
}
public int[] ResultValues
{
get
{
int[] values = new int[results.Length];
for (int i = 0; i < results.Length; i++)
values[i] = (int)Math.Round(results[i]);
return values;
}
}
internal void AddOffset(DataLine offset) { this.offset = offset; }
internal void AddBaseLine(DataLine baseline) { this.baseline = baseline; }
internal void AddResults(float[] results) { this.results = results; }
#endregion
}
}