如何将下列SQL语句转换为LinqToSQL语句?将SQL语句转换为Linq
select field, 1 as ordering from table where field2 = condition1
union all
select field, 7 as ordering from table where field2 = condition2
union all
select field, 3 as ordering from table where field2 = condition3
union all
select field, 2 as ordering from table where field2 = condition4
order by ordering
实际上,我只是加入了几个查询,并根据行的原点排序了结果集。
我可以管理联合,如下所示,但我似乎无法让LinqToSQL订购整个结果集,我只能得到它来订购每个单独的查询。
from t in table
where
condition
select new { field, ordering = 1 }
).Union
(
from t2 in table2
where
condition
select new { field ordering = 7 }
).Union
(
from t3 in table3
where
condition
select new { field ordering = 3 }
).Union
(
from t4 in table4
where
condition
select new { field ordering = 2 }
);
这正是我之后 - 谢谢。 – user9659 2009-07-22 07:44:06