【发布时间】:2014-09-14 10:47:07
【问题描述】:
我有一个名为 Table1 的表,其中包含以下列
ID, Foo, Bar, DateTime
ID 是主键
我正在尝试从表中获取具有 foo 和 bar 的最后一行作为
参数。
我只想获取最近的一行(按DateTime排序)
public void DoIt(string foo, string bar)
{
using (var context = new DataModelContainer())
{
var obj = (from m in context.Table1
where m.Foo == foo && m.Bar == bar
select m).LastOrDefault();
if (obj != null)
{
DoSomthing()
context.SaveChanges();
}
}
}
【问题讨论】: