将SQL查询转换为LINQ to SQL查询

时间:2011-02-25 06:45:32

标签: linq linq-to-sql

如何使用LINQ编写此查询?

SELECT CAST(CASE WHEN [IsForReplication] = 1  THEN 'Yes' 
                   ELSE 'No' END AS NCHAR) as [IsForReplication], * 
FROM [SAN].[dbo].[PolicyInterval]

2 个答案:

答案 0 :(得分:2)

var query = from pi in context.PolicyInterval
            let IsForReplication = pi.IsForReplication ? "Yes" : "No"
            select new
            {
                IsForReplication,
                PolicyInterval = pi,
            };

答案 1 :(得分:0)

var result = PolicyInterval.Select(entry => new {IsForReplication = entry.IsForReplication.Equals(1).ToString(), data = entry});