根据LINQ to SQL中的变量选择列 [英] Select column based on variable in LINQ to SQL
本文介绍了根据LINQ to SQL中的变量选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序中的C#中使用LINQ to SQL.我需要能够选择一行的列,具体取决于变量.对于行而言,这很容易,因为它是一个简单的where子句,但我只能选择特定的列而感到迷惑.到目前为止,这是我的代码:
I'm using LINQ to SQL in C# in my application. I need to be able to select a column of a row, depending upon a variable. This is easy for the row as it's a simple where clause, but I'm at a loss with only selecting a specific column. Here is my code so far:
var permissions = (from s in dc.Permissions where s.dashboardname == permission select s.[variablehere]).Single();
这容易实现吗?
推荐答案
是否可以更改数据库结构,以使您的列变为行? (旋转您的桌子吗?)
Is it possible to change your database structure so that your columns becomes rows? (Pivot your table?)
例如.
Permissions Table
-----------------
Id
Dashboardname
Page1
Page2
Page3
...
并将其变成
Permissions Table
-----------------
Id
Dashboardname
Pagename
然后您可以使用where子句选择所需的行?
Then you could use the where clause to select the row you want?
这篇关于根据LINQ to SQL中的变量选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文