在C#中使用字符串值作为变量名称

发布于 2025-02-05 08:28:42 字数 384 浏览 2 评论 0原文

我的字符串正在剃须刀页面传递给我的控制器。该字符串包含用户选择的8个可能布尔值之一的名称。我试图在SQL Server查询中使用此布尔名称,如下所示。

try
{
     var test = await _context.GuestModel
     .Include(r => r.PatientModel)
     .OrderByDescending(r => r.GuestLastName)
     .Where(r => r.booleanName  == true)
     .ToListAsync();
     return test;
}

Booleanname是包含我需要使用的布尔名称的字符串,但是到目前为止,我无法成功访问该信息。

I have a string that is being passed to my controller in Razor Pages. This string contains the name of one of 8 possible Booleans as selected by the user. I am attempting to use this Boolean Name in a SQL server query as shown below.

try
{
     var test = await _context.GuestModel
     .Include(r => r.PatientModel)
     .OrderByDescending(r => r.GuestLastName)
     .Where(r => r.booleanName  == true)
     .ToListAsync();
     return test;
}

booleanName is the string containing the Boolean Name I need to use, but so far I have not been able to access that information successfully.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千紇 2025-02-12 08:28:42

如果/else 块,请使用switchblocks从基于字符串的查询中的八个可能版本之一中选择。

Use a switch or if/else blocks to pick from one of eight possible versions of the query based on the string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文