[英]Retrieving biggest decimal value from a local .mdf Database c#
我在Microsoft Visual Studio 2013中创建了一个非常简单的SQL Server数据库,称为Personnel.mdf
。在此数据库中,我有一个名为Employee
的表,其定义如下:
现在,我试图获得最高的时薪,并将其输出到我创建的表单中的消息中。 我在项目中创建了Personnel
数据库的ADO.NET实体数据模型,此刻使用了它的一个实例。
有人有任何想法我该怎么做吗? 让我知道您是否需要更多信息。
使用Entity Framework和Linq-to-Entities,请尝试如下操作:
// using your database context - adapt to your DbContext class!
using (testEntities ctx = new testEntities())
{
// sort employees descending by hourly pay rate - take the first
Employee highestPaidEmployee = ctx.Employee.OrderByDescending(e => e.HourlyPayRate)
.FirstOrDefault();
Console.WriteLine("Your highest paid emplyoee is: {0} with an hourly pay rate of {1}", highestPaidEmployee.Name, highestPaidEmployee.HourlyPayRate);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.