简体   繁体   English

使用实体框架linq从数据库结果中获取项目

[英]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 我需要第四列的值,其中NameMineScheduleId5

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.

相关问题 如何使用linq和C#中的实体框架从另一个表中获取对象中的项目列表? - how to get a list of item in object from another table using linq and entity framework in C#? 从数据库获取所有表,并使用C#,Linq查询和Entity Framework遍历每个表 - Get all tables from database and loop through each table using C#, Linq query and Entity Framework 使用LINQ完善实体框架结果集 - Refining an Entity Framework result set using LINQ 使用实体框架从数据库获取行 - Get rows from database using the Entity framework 如何首先从实体框架+数据库中的存储过程中获取结果 - how to get the result from stored procedure in entity framework + database first 如何使用Linq和C#在实体框架中获取多个结果集? - How to get Multiple Result Set in Entity Framework using Linq with C#? 为什么我从两个几乎相同的表达式获得不同的结果,以使用Entity Framework上下文从数据库获取数据 - Why I am getting different result from two almost equal expressions to get data from database using Entity Framework context 如何使用Linq从实体框架中进行设置 - How to set this from Entity Framework using Linq 使用Entity Framework从SQL数据库中获取所有内容 - Get All Except from SQL database using Entity Framework 使用实体框架从数据库获取前N行 - Get first N Rows from Database using Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM