[英]Cannot access the field value from the Linq query EF Core
I am trying to build a .NET core application that uses EF core and alos using Caching to store some of the query response.我正在尝试构建一个 .NET 核心应用程序,该应用程序使用 EF 核心并使用缓存来存储一些查询响应。 I am having issue with accessing fields from the LINQ query response.我在访问 LINQ 查询响应中的字段时遇到问题。 I am not sure what is that I am missing here.我不确定我在这里缺少什么。 There is a Setting table in the SQL Server DB and the model is like below SQL Server DB中有一个Setting表,模型如下
public partial class Setting
{
public string EndTime { get; set; }
public string StartTime { get; set; }
public string OrderDay { get; set; }
public int SettingsId { get; set; }
}
and trying to query it like below in a Controller called CustomersController并尝试在名为 CustomersController 的控制器中像下面一样查询它
public class CustomersController : Controller
{
............
IQueryable<JAXSurplusMouseApp.Models.Setting> settings_data = null;
.....................
bool isSettingExist = memoryCache.TryGetValue("SMSettings", out settings_data);
if (!isSettingExist)
{
string myCondition = (todayDt.DayOfWeek.ToString().Substring(0, 3)).ToUpper();
settings_data = (from s in _context.Settings
where s.OrderDay == myCondition
select s).Take(1);
var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromHours(2));
memoryCache.Set("SMSettings", settings_data, cacheEntryOptions);
}
if(settings_data.Count() != 0)
{
stringstart_time = settings_data.StartTime;
}
I get error like 'IQueryable<Setting>' does not contain a definition for 'StartTime' and no accessible extension method 'StartTime' accepting a first argument of type 'IQueryable<Setting>' could be found (are you missing a using directive or an assembly reference?)
I am sure I am missing something here but not sure what is that I am missing any help is greatly appreciated我收到诸如'IQueryable<Setting>' does not contain a definition for 'StartTime' and no accessible extension method 'StartTime' accepting a first argument of type 'IQueryable<Setting>' could be found (are you missing a using directive or an assembly reference?)
类'IQueryable<Setting>' does not contain a definition for 'StartTime' and no accessible extension method 'StartTime' accepting a first argument of type 'IQueryable<Setting>' could be found (are you missing a using directive or an assembly reference?)
错误'IQueryable<Setting>' does not contain a definition for 'StartTime' and no accessible extension method 'StartTime' accepting a first argument of type 'IQueryable<Setting>' could be found (are you missing a using directive or an assembly reference?)
我确定我在这里遗漏了一些东西,但不确定我遗漏了什么任何帮助都非常感谢
:) :)
Issue mainly is that it's an IQuerable<> still and you need the actual instance:问题主要是它仍然是 IQerable<> 并且您需要实际实例:
stringstart_time = settings_data.First().StartTime;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.