[英]Get item from database result by using entity framework linq
I have a schedule object that is returned from the database. 我有一个从数据库返回的计划对象。 It contains information from a few tables.
它包含来自几个表的信息。 One of the tables is called ScheduleData and has four columns.
其中一个表称为ScheduleData,有四列。 It has this format:
它有这种格式:
Id | ScheduleId | Name | Value
I need the value of the fourth column where the Name
is Mine
and the ScheduleId
is 5
我需要第四列的值,其中
Name
是Mine
, ScheduleId
是5
I have tried this, but it doesn't work: 我试过这个,但它不起作用:
string val = from s in schedule.ScheduleData where s.Name.Equals("Mine") && s.ScheduleId == 5 select s.Value;
Use First
method or FirstOrDefault
method.The query returns an IEnumerable<T>
, you can't assign it to string
. 使用
First
方法或FirstOrDefault
方法。查询返回IEnumerable<T>
,您不能将其分配给string
。
string val = (from s in schedule.ScheduleData
where s.Name == "Mine" && s.ScheduleId == 5
select s.Value).First();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.