switch语句中的LINQ [英] switch statement in linq
问题描述
我的code使用LINQ SQL连接是:
My code for sql connection using linq is:
var query1 = from u in dc.Usage_Computers
where u.DomainUser == s3
select u; // selects all feilds from table
GridView1.DataSource = query1;
GridView1.DataBind();
我有一个被称为操作的表格Domainuser具有像1,2,3值的字段。当我填充这些值数据网格,我想将它们转换为有意义的值一样,如果操作的值是1,那么在数据网格的登录显示,如果2然后在注销等等...
I have a field called "Operation" in the table "Domainuser" which has values like "1, 2, 3". When I populate these values to data grid I wanted to convert them to meaningful values like if the value of Operation is 1 then display in datagrid as "logon", if 2 then "logoff" etc...
我如何从数据库中检索后为它们分配值?
How do i assign values for them after retrieving from database?
推荐答案
这个技术似乎并不特别适用于您的问题,但在这里它是无论如何。
This technique does not seem particularly applicable to your problem, but here it is anyway.
您可以使用C#的创建一个LinqToSql的SQL case语句? 运营商。
You can create a SQL case statement in LinqToSql by using the C# ? : operator.
var query1 =
from u in dc.Usage_Computers
where u.DomainUser == s3
select new {usage = u,
operation =
u.DomainUser.Operation == 1 ? "login" :
u.DomainUser.Operation == 2 ? "logoff" :
"something else"
};
这篇关于switch语句中的LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!